【发布时间】:2015-11-09 17:54:41
【问题描述】:
测试场景:
- 在文本框中输入“hello”,您应该会在页面中看到“hello”
- 现在点击“测试”链接(它只是一个指向自身的链接,带有查询字符串
&test=1) - 现在在文本框中输入“world”,您可以看到它不再写在页面中了。
为什么会这样?
您可以在.php 页面上测试此页面:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<form id="search_form" method="post">
<label for="search">Search:</label>
<input type="search" id="search" />
</form>
<script type="text/javascript">
$('#search_form').submit(function (event) {
window.location.href = '<?=$_SERVER['PHP_SELF'].'?s='?>' + $('#search').val();
event.preventDefault();
});
</script>
<br /><br />
<?php $s = filter_input(INPUT_GET, 's'); ?>
Query string: <?=$s?>
<br /><br />
<a href="<?=$_SERVER['PHP_SELF']?>?s=<?=$s?>&test=1">test</a>
</body>
</html>
演示网址:(问题解决后删除)
【问题讨论】:
-
请详细说明第二次发生了什么
-
@Diego 我希望表单能够正常工作(例如,打印用户在 texbox 中输入的内容),即使在单击“测试”链接之后也是如此。
-
@M.Doye 谢谢。我从未使用过或见过它。会检查的。
-
@IMB,效果很好!!
-
另外,由于您使用的是 JQM,您可能需要将
data-ajax="false"添加到您的A测试标签中。
标签: javascript php jquery html jquery-mobile