我想根據選擇標籤中選擇的內容更改輸入標籤中寫入的內容。選擇標籤上的JavaScript更改功能
這是我的選擇標籤
<div class="form-group col-lg-4">
<label for="donationType">Donation Type: </label>
<select id="donationType" style="text-transform: capitalize"
name="volunteerProject.donationTypeId" class="form-control">
<option value='0'>Select Donation Type</option>
<s:iterator value="donationTypeList">
<option value='<s:property value="donationTypeId" />'
name='<s:property value="donationType" />'>
<s:property value="donationType" />
</option>
</s:iterator>
</select>
</div>
,這是我的輸入標籤
<div class="form-group col-lg-3" id="vpDonateButtonLabelDiv">
<label for="vpTitle">Button Label</label> <input
type="text" class="form-control" id="vpDonateButtonLabel"
name="volunteerProject.donateButtonLabel"
placeholder="Enter button label" maxlength="50" required />
</div>
,這裏是我的javascript代碼
$('#donationType').change(function() {
var donationType = $(this).val();
if (donationType != 0) {
if (donationType == 1){
$("#vpDonateButtonLabelDiv").append('Donate');
} else if (donationType == 2) {
$("#vpDonateButtonLabelDiv").append('Volunteer');
} else if (donationType == 3) {
$("#vpDonateButtonLabelDiv").append('Share');
} else if (donationType == 5) {
$("#vpDonateButtonLabelDiv").append('Tweet');
}
} else {
$("#vpDonateButtonLabelDiv").append('');
}
});
但是,它不工作。我在這裏錯過了什麼?或者我的方法錯了?非常感謝
這正是我所需要的,但即使我遵循了你提到的內容,它也不起作用。我會仔細檢查我的後端過程,謝謝! – chiliflavor
我還在我的答案中提供了演示鏈接。如果您對此處有任何疑問而不是評論。 –
終於!現在一切正在進行中,問題在於我的瀏覽器無法識別我所做的最近更改。我清空緩存並重新加載瀏覽器後解決了問題。非常感謝@kalpesh! – chiliflavor