我尝试做的是抓取文本然后将该文本提交到特定的应用程序,其中表单输入名称=" mykeyword"被接受,我也想在浏览器的新标签中打开它。
我做了一些练习但没有运气。有什么想法吗?
$("#ScanTitle").click(function () {
var mykeyword = $("#mykeyword").text();
// the 'mykeyword' variable will be submitted to 'Search/Index' route with INPUT name='mykeyword' form attribute in new window
$.post('Search/Index', function (data) {
var w = window.open('about:blank', 'windowname');
w.document.write(data);
w.document.close();
});
});

<!DOCTYPE html>
<html>
<head>
<title>test</title>
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<button id="ScanTitle">button</button>
<p id="mykeyword">hand bags</p>
</body>
</html>
&#13;
答案 0 :(得分:1)
您需要将参数提供给$.post
:
$.post('Search/Index', {name: myKeyword}, function(data) {
var w = window.open('about:blank', 'windowname');
w.document.write(data);
w.document.close();
});
要绕过弹出窗口阻止程序,您需要在单击处理程序中打开窗口,而不是AJAX回调。
$("#ScanTitle").click(function() {
var mykeyword = $("#mykeyword").text();
var w = window.open('about:blank', 'windowname');
$.post('Search/Index', {name: myKeyword}, function(data) {
w.document.write(data);
w.document.close();
});
});