문제

I would currently like to dynamically add an anchor to a data-role = "header" div. I currently have the following code:

HTML

<div data-role ="header">
     <div  id="SignUp"></div>
</div>

Javascript

$('#SignUp').append('<a data-icon="star" href="#" data-role="button" id="SignUpLink">Sign Up</a>');
$("#SignUpLink").trigger('create');

The problem I am having is that the it's not producing the following:

enter image description here

But rather the code found Here. I've tried to refresh the SignUpLink with .trigger() and .button('refresh'). But that also doesn't seem to work. I'm not really not sure how to fix the problem found in the jsFiddle...

도움이 되었습니까?

해결책

Working example: http://jsfiddle.net/Gajotres/AtKhs/

When appending content to page header or footer another function must be used.

.trigger('pagecreate');

Unlike trigger('create') which enhances only content, trigger('pagecreate') will try to enhance everything.

Read more about it in my blog article HERE, look for a chapter called: Enhance a full page content. Working example can be found there.

다른 팁

This problem can be solved much more easily this way: swapping .trigger("create") place:

$('#SignUp').append('<a data-icon="star" href="#" data-role="button" id="SignUpLink">Sign Up</a>').trigger('create');

test and see which will work perfectly and save lines of code.

with this you eliminate the second line

$("#SignUpLink").trigger('create');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top