English 中文(简体)
重置图像动作
原标题:image for reset action

I am using an image instead of a reset button n html-php.I wrote a javascriptfunction to clear all the text box values,but it reloads the entire page,so that again the values appear in the textbox when reloading the page,when the image button for reset action is clicked .. My code is

<script type="text/javascript">
function clearall() {
$(".tinput").val(  );
$(".tinput1").val(  );
}
</script>

我不想让页面重新加载,但只清除所有文本字段。

问题回答

使用此选项 :

<script type="text/javascript">
function clearall() {
$(".tinput").val(  );
$(".tinput1").val(  );
return false;
}
</script>

看来你的表格已经递交了

您需要停止按钮的默认动作, 要这样做, 您必须调用 < code> 。 防止事件发生时的 Default () 方法, 或者从处理器中调用 < code> return 假

您也可以使用窗体 s . reset () 方法 。

function resetForm(callingElement) {
   callingElement.form.reset();
   return false;
}

并使用

Demo在 http://jsfidd.net/gaby/3R2TX/


由于您正在使用 jQuery, 您可以将它简化到

function resetForm(e) {
   e.preventDefault();
   this.form.reset();
}

应用并应用

 $( #id_of_reset_button ).click(resetForm);

jQuery Demoat http://jsfidd.net/gaby/3R2TX/1/

当拥有超超链接或提交按钮时, 您的函数必须返回 FALSE, 以便停止处理

<img id="reset" src="" />

<script type="text/javascript">
  $("#reset").click(function(){
    $(".tinput").val(  );
    $(".tinput1").val(  );
  });
</script>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签