Javascript 如何更改html中输入类型的值?
我有一个简单的html表单Javascript 如何更改html中输入类型的值?,javascript,jquery,html,html-input,Javascript,Jquery,Html,Html Input,我有一个简单的html表单 <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top" id="registration-form"> <input type="text" class="form-control" name="form-reg-fullname" data-form-field="Name" id="form-reg-fullna
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top" id="registration-form">
<input type="text" class="form-control" name="form-reg-fullname" data-form-field="Name" id="form-reg-fullname">
<input type="hidden" name="return" value=""/>
</form>
在
标记中,我正在进行验证并更改返回值:
<script>
$('#registration-form').submit(function () {
var fname = $.trim($('#form-reg-fullname').val());
$("#return").val("http://localhost:9000/app/fname");
});
</script>
$(“#注册表”)。提交(函数(){
var fname=$.trim($('#form reg fullname').val());
$(“#返回”).val(“http://localhost:9000/app/fname");
});
提交表单时验证工作成功,但我在
返回输入类型中得到空值。我怎样才能让它工作 看起来您在返回输入中缺少一个id,您只有一个名称。所以它应该是这样的:
<input type="hidden" name="return" id="return" value=""/>
这样,当您使用$('#return')
调用js中的输入时,它将通过正确的id获取它
<input type="hidden" name="return" value=""/>
$("#return").val("http://localhost:9000/app/fname");//PROBLEM RESIDE Here
或者,您可以将id属性指定给输入元素,如下所示:
<input type="hidden" id="return" name="return" value=""/>
您正在使用不存在的id=“return”
分配输入值
$("#return").val("http://localhost:9000/app/fname");
您应该为输入标记指定一个id作为
<input type="hidden" name="return" id="return" value=""/>
在jquery中使用id调用节点,返回输入没有名为return的id
$('#注册表')。提交(函数(){
var fname=$.trim($('#form reg fullname').val());
$(“#返回”).val(“http://localhost:9000/app/fname“”;//设置值
console.log($(“#return”).val();//获取值
});代码>
<input type="hidden" name="return" id="return" value=""/>
$("input[name='return']").val("http://localhost:9000/app/fname");