[英]jQuery - how to get the value of an input of type submit when ajaxifying a form
[英]Change value of input when input type=submit
我有一個類似下面的輸入:
<input class="submit" type="submit" name="submit" value="Blah">
我想將值更改為“其他文本”。 當我使用.val(),attr()或.prop()jQuery方法時,該值會很好地改變,但是當我提交時,輸入將不再起作用。只需刷新頁面而不執行其應有的工作即可。
與.setAttribute方法相同的結果。
值更改后,如何使輸入正常工作?
嘗試這個
<input type=button name="b1" value="Submit" onclick="javascript:document.MyForm.b1.value='Done'">
來源: 提交后在“提交”按鈕上更改文本
檢查一下
$(document).ready(function(){ $(".submit").click(function(){ $(this).val("OtherText"); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input class="submit" type="submit" name="submit" value="Blah">
您可以阻止提交表單或在按鈕單擊事件中:
$(".submit").click(function(e){
e.preventDefault();
$("#inputbox").val("OtherText");
//Now you can submit form manually here
$("#form").submit();
});
我認為是服務器端腳本正在檢查該值,因此單擊時必須將其更改回原來的值。
if ($('.submit').length > 0) {
$('.submit').prop('value', 'Other Text');
$('.submit').click(function(){
$('.submit').prop('value', 'blah');
});}
現在看來這工作正常。 不理想但是可以
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.