Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
742 views
in Technique[技术] by (71.8m points)

javascript - preventDefault in Safari

I have a textbox which has the code;

<input type="text" maxlength="5" size="2" value="1" id="paging_textbox">

Now there is no encloding form tag on this page..

When user types in this textbox and presses Enter, the table on this page is updated (via AJAX call)

In Safari, the behavior is slightly different in the sense that even though it updates the table correctly, it kind of reloads the page (think it submits the form, but not sure how as there is no form tag) and resets the textbox value back to "1"

How do I prevent this from happening in Safari ?

Please help me. Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just to be sure, terminate your callback function with a return false. That should do the trick.

 function(e) {
     e.preventDefault();
     // some awesome code
     return false;
 }

Oh, and another thing: in the future, to avoid such random behavior.. respect the standards, use a form :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...