2013-05-02 85 views
1

我有一個JQuery Mobile/Phonegap應用程序。動態插入HTML表格元素後我打電話.trigger('create')包含元素上,像這樣:動態內容只在JQuery Mobile/Phonegap中部分樣式

$('div#response-form').append(formHtmlString).trigger('create'); 

所有元件被正確地風格除單選按鈕和複選框,其中僅部分的風格和還沒有正確對齊。請參見下面附加的圖像:

Dynamic form in JQuery Mobile

這到底我做錯了什麼?

謝謝!

編輯

這是包含在formHTMLString變量的HTML代碼:

<form data-response_id="API1201344135246"> 
<div data-page="1"> 
    <h3>Page One</h3> 
</div> 
<div data-role="fieldcontain"> 
    <fieldset data-role="controlgroup"> 
     <legend>Question - Checkbox*</legend> 
     <input type="checkbox" name="10010" id="10010" value="One" class="custom" /> 
     <label for="10010">One</label> 
     <input type="checkbox" name="10011" id="10011" value="Two" class="custom" /> 
     <label for="10011">Two</label> 
     <input type="checkbox" name="10012" id="10012" value="Three" class="custom" /> 
     <label for="10012">Three</label> 
    </fieldset> 
</div> 
<div data-role="fieldcontain"> 
    <label for="2">Question - String*</label> 
    <input type="text" name="2" id="2" value="" /> 
</div> 
<div data-role="fieldcontain"> 
    <fieldset data-role="controlgroup"> 
     <legend>Question - Radio Button</legend> 
     <input type="radio" name="6" id="10004" value="Yes" /> 
     <label for="10004">Yes</label> 
     <input type="radio" name="6" id="10005" value="No" /> 
     <label for="10005">No</label> 
     <input type="radio" name="6" id="10006" value="Maybe" /> 
     <label for="10006">Maybe</label> 
    </fieldset> 
</div> 

.... 

</form> 

回答

1

更新:

如果你想使用你的自定義主題/風格,負荷的jQuery - 移動設備的默認CSS並覆蓋它的'樣式。


增強的動態使用既.checkboxradio().trigger('create')複選框和單選按鈕的標記。

複選框:

$('input[type=checkbox]').checkboxradio().trigger('create'); 

單選按鈕:

$('input[type=radio]').checkboxradio().trigger('create'); 

Demo

+1

1爲一個正確的答案 – Gajotres 2013-05-02 08:57:23

+0

'$('body')。trigger('create');'也可以在你的演示中使用(請參閱http://jsfiddle.net/X43HK/),但在我的應用程序中都不起作用,所以調用'在父容器上觸發('創建')應該已經完成​​了。你會看到它是__partially__樣式,所以它確實會做__something__。這個問題似乎有點複雜。任何其他想法? – 2013-05-02 09:58:47

+0

@raouldeveloper最好發佈你的HTML標記。 – Omar 2013-05-02 14:26:26