3 回答

TA貢獻1829條經(jīng)驗 獲得超9個贊
假設(shè)在您提交之后頁面刷新并且表單中的值被維護,您可以將您的 jQuery 修改為:
<script type="text/javascript">
jQuery(function() {
var nationalothers = $('#OthersNationalityInput');
if (this.value == 'Others') {
nationalothers.show();
} else {
nationalothers.hide();
}
});
jQuery(document).on('change', '#NationalitySelect', function() {
var nationalothers = $('#OthersNationalityInput');
if (this.value == 'Others') {
nationalothers.show();
} else {
nationalothers.hide();
}
});
</script>
但是當(dāng)然你應(yīng)該通過保持干燥來優(yōu)化上面的代碼。

TA貢獻1833條經(jīng)驗 獲得超4個贊
你可以通過改變這一行來做到這一點
<input type="text" style="display:none;" name="others_nationality" class="form-control" id="OthersNationalityInput" value="<?php echo ($others_nationality) ?>" />
到
<input type="text" style="display:<?php echo ($nationality=='Others' ? 'block' : 'none'); ?>" name="others_nationality" class="form-control" id="OthersNationalityInput" value="<?php echo ($others_nationality) ?>" />

TA貢獻1854條經(jīng)驗 獲得超8個贊
當(dāng)您提交頁面時,它會被刷新以使其消失。嘗試在表單提交時通過 PHP 添加文本框
if(isset($_POST['submit']))
{
echo"<input type='text' val='value from database'/>";
}
- 3 回答
- 0 關(guān)注
- 210 瀏覽
添加回答
舉報