문제

I have to dynamically generate HTML-Code that uses jKnob.

This code does work:

<input id="dialSeconds" data-cursor="true" class="dial" data-width="125" data-height="125" data-thickness="0.275" data-min="0" data-max="59" 
                       data-readOnly="true" data-displayInput="false"
                       data-fgcolor="#999" value="59" style="position: relative !important; margin-top: -300px !important; color:#999 !important;" />

This code does not work:

function ShowKnob() {
  var knob="<input id=\"dialSeconds\" data-cursor=\"true\" class=\"dial\" data-width=\"125\" data-height=\"125\" data-thickness=\"0.275\" data-min=\"0\" data-max=\"59\" data-readOnly=\"true\" data-displayInput=\"false\" data-fgcolor=\"#999\" value=\"59\" style=\"position: relative !important; margin-top: -300px !important; color:#999 !important;\" />";
$('#knob').html(knob)
}
<div id='knob'>boom</div>

(The content is generated but without any style or knob functionality) So to shorten it up: The knob works when entered as HTML, but not when generated dynamically by JS.

도움이 되었습니까?

해결책

You are missing a call to .knob();.

Try this:

function ShowKnob() {
  var knob="<input id=\"dialSeconds\" data-cursor=\"true\" class=\"dial\" data-width=\"125\" data-height=\"125\" data-thickness=\"0.275\" data-min=\"0\" data-max=\"59\" data-readOnly=\"true\" data-displayInput=\"false\" data-fgcolor=\"#999\" value=\"59\" style=\"position: relative !important; margin-top: -300px !important; color:#999 !important;\" />";
$('#knob').html(knob);
$('#knob').knob();
}
<div id='knob'>boom</div>

And see in action here: http://jsfiddle.net/tp8Xp/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top