我已經查看了所有的答案,我認爲這會是一個比較簡單的問題。我所看到的所有答案都表示使用'.text()'不起作用。jquery mobile:更改列表視圖的標題
在jquery mobile中,我想簡單地用列表視圖中選擇的單選按鈕的文本替換列表視圖中的標題文本。爲了簡單起見,只需動態更改列表視圖中的標題文本就足夠了。問題是我不能動態地改變列表視圖的標題的文本,而不刪除一些HTML。我試圖從計算器提出了許多建議和其他網站,包括:
Jquery Mobile: Dynamically change the text of the header of a collapsible div?
https://forum.jquery.com/topic/how-can-i-dynamically-change-the-text-of-a-collapsible
jQuery mobile: Dynamically updating collapsible heading causes loss of styling
我使用以下的Android設備上測試:
- 科爾多瓦版本:6.3.1
- JQuery的1.11.0
- jQuery Mobile的1.4.5
HTML:
<div data-role="page" id="test">
<div role="main" class="ui-content">
<div class="ui-grid-a multiple-inputs">
<div class="ui-block-a">
<ul data-role="listview" data-inset="true" data-shadow="false">
<li data-role="collapsible" data-iconpos="right" data-inset="false">
<h2 id="h2-test-area">Area</h2>
<form>
<fieldset data-role="controlgroup">
<input type="radio" name="rad-test-area" id="rad-test-area-0-1" value="0">
<label for="rad-test-area-0-1">Abdomen</label>
<input type="radio" name="rad-test-area" id="rad-test-area-1-1" value="1">
<label for="rad-test-area-1-1">Arms</label>
<input type="radio" name="rad-test-area" id="rad-test-area-2-1" value="2">
<label for="rad-test-area-2-1">Outer thigh</label>
<input type="radio" name="rad-test-area" id="rad-test-area-3-1" value="3">
<label for="rad-test-area-3-1">Inner thigh</label>
<input type="radio" name="rad-test-area" id="rad-test-area-4-1" value="4">
<label for="rad-test-area-4-1">Calves</label>
<input type="radio" name="rad-test-area" id="rad-test-area-5-1" value="5">
<label for="rad-test-area-5-1">Flanks</label>
<input type="radio" name="rad-test-area" id="rad-test-area-6-1" value="6">
<label for="rad-test-area-6-1">Chest</label>
<input type="radio" name="rad-test-area" id="rad-test-area-7-1" value="7">
<label for="rad-test-area-7-1">Buttocks</label>
<input type="radio" name="rad-test-area" id="rad-test-area-8-1" value="8">
<label for="rad-test-area-8-1">Back (lower and upper)</label>
<input type="radio" name="rad-test-area" id="rad-test-area-9-1" value="9">
<label for="rad-test-area-9-1">Jaw line</label>
<input type="radio" name="rad-test-area" id="rad-test-area-10-1" value="10">
<label for="rad-test-area-10-1">Chin</label>
<input type="radio" name="rad-test-area" id="rad-test-area-11-1" value="11">
<label for="rad-test-area-11-1">Knee</label>
</fieldset>
</form>
</li>
</ul>
</div>
<div class="ui-block-b">
<ul data-role="listview" data-inset="true" data-shadow="false">
<li data-role="collapsible" data-iconpos="right" data-inset="false">
<h2>Relevant treatments:</h2>
<form>
<fieldset data-role="controlgroup">
<input type="checkbox" name="cb-test-1" id="cb-test-1-1">
<label for="cb-test-1-1">Fillers</label>
<input type="checkbox" name="cb-test-1" id="cb-test-1-2">
<label for="cb-test-1-2">Botox</label>
<input type="checkbox" name="cb-test-1" id="cb-test-1-3">
<label for="cb-test-1-3">Dermaroller</label>
<input type="checkbox" name="cb-test-1" id="cb-test-1-4">
<label for="cb-test-1-4">HydraFacial</label>
<input type="checkbox" name="cb-test-1" id="cb-test-1-5">
<label for="cb-test-1-5">FSR</label>
<input type="checkbox" name="cb-test-1" id="cb-test-1-6">
<label for="cb-test-1-6">Laser</label>
<input type="checkbox" name="cb-test-1" id="cb-test-1-7">
<label for="cb-test-1-7">Ping</label>
<input type="checkbox" name="cb-test-1" id="cb-test-1-8">
<label for="cb-test-1-8">Endymed</label>
<input type="checkbox" name="cb-test-1" id="cb-test-1-9">
<label for="cb-test-1-9">Chemical Peel</label>
<input type="checkbox" name="cb-test-1" id="cb-test-1-10">
<label for="cb-test-1-10">Aqualyx</label>
<input type="checkbox" name="cb-test-1" id="cb-test-1-11">
<label for="cb-test-1-11">Hyalase</label>
<input type="checkbox" name="cb-test-1" id="cb-test-1-12">
<label for="cb-test-1-12">Tretinion and Hydroquinone (Obagi)</label>
</fieldset>
</form>
</li>
</ul>
</div>
</div><!-- /grid-a -->
</div><!-- /content -->
</div><!-- /test page -->
這是HTML什麼,我試圖操縱的樣子呈現前:
<h2 id="h2-test-area">Area</h2>
文本「區域」是我想要改變的。
這是HTML什麼,我試圖操縱看起來像渲染後:
<h2 id="h2-test-area" class="ui-collapsible-heading">
<a href="#" class="ui-collapsible-heading-toggle ui-btn ui-btn-icon-right ui-btn-inherit ui-icon-minus">
Area
<span class="ui-collapsible-heading-status"> click to collapse contents</span>
::after
</a>
</h2>
的Javascript:
$("input[name='rad-test-area']").on("change", function() {
$("#h2-test-area a.ui-collapsible-heading-toggle").text("new text");
});
當我執行上述的javascript它取代了文字我想它,但它也會替換HTML中文本「區域」之後出現的範圍。爲什麼每個人都說'.text()'在清除HTML時會起作用?預先感謝您的任何幫助。
謝謝,這很容易,我做到了。我想我只是認爲,jQuery的手機應該有一個更簡單的方式來操縱ListView標題。 – ModusPwnens