我有下面的代码。我将在文本区域中放置一个值列表。并且 iframe 应该将 a 行中的值连接到硬编码的 URL,当我单击下一步时,它应该连接下一行的值;当我单击上一行中的值时。
<HTML>
<Head>
<button>Previous</button>
<button>Next</button>
<textarea rows="10" cols="20">
Values here
</textarea>
</br>
</head>
<body>
<iframe src="http://www.domain.com/"*&rowValue from the textarea* height="1200px" width="1200px">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</HTML>
这是@Adeneo 回复后的代码: 这是我使用您的参考编写的代码,但我无法让它工作。此外,如果可能的话,脚本是否还可以在 iframe 上方显示我当前正在查看的 ASIN?
<HTML>
<Head>
<button id="prev">Previous</button>
<button id="next">Next</button>
<textarea rows="10" cols="20" value="">
ASINs here
</textarea>
<button id="go">Go</button>
<br/>
</head>
<body>
<iframe id="myframe" src="http://www.amazon.co.uk/dp/" height="100%" width="100%">
<p>Your browser does not support iframes.</p>
</iframe>
<script>var domain='http://www.amazon.co.uk/dp/';
$('#prev, #next').on('click', function(e) {
var Myval = $('textarea').val().split('\n'),
now = $('#myframe').attr('src').replace(domain, '');
if (Myval.indexOf(now)==-1) {
var src=domain+Myval[0];
}else{
var p = Myval.indexOf(now)!==0 ? Myval.indexOf(now)-1 : Myval.length-1,
n = Myval.indexOf(now)==(Myval.length-1) ? 0 : Myval.indexOf(now)+1,
src = e.target.id=='next' ? domain+Myval[n] : domain+Myval[p];
}
$("#myframe").attr('src', src);
console.log(src);
});
?
</script>
</body>
</HTML>
非常感谢!