我正在做一些属性解析为字符串,所以我需要知道HTML/XHTML元素属性中如何使用空格:
<div id='myid' width='150px' />
Run Code Online (Sandbox Code Playgroud)
这也是正确的吗?
<div id = 'myid' width = '150px' />
Run Code Online (Sandbox Code Playgroud)
如果有人知道使用JavaScript迭代属性及其值的其他方法,我有兴趣知道.
过去几个小时我一直在尝试更改 iFrame 的 src。这似乎是一个简单的任务,但由于某种原因,经过数百次尝试并阅读了堆栈上的许多其他问题和答案后,我仍然发现自己无法更改 iFrame 的 src。正如您从下面的代码中看到的,我已经尝试过很多次了。我究竟做错了什么?
<body>
<p><iframe src="http://localhost/ok.html" name="myFrame" width="500" marginwidth="0" height="500" marginheight="0" align="middle" scrolling="auto"></iframe>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
function loadPages(){
var loc = "http://localhost/morningmarketweb/index.html";
//var myIframe = document.getElementById("myFrame");
//window.frames[myIframe].location = "http://localhost/morningmarketweb/index.html";
// $(myIframe).load('http://localhost/morningmarketweb/index.html');
// document.getElementId('myFrame').src="google.com";
// var myIframe = document.getElementById('myFrame');
// myIframe.src=loc;
//$('#myFrame').attr('src', loc);
document.getElementById('myFrame').setAttribute('src', loc);
}
</script>
</body>
Run Code Online (Sandbox Code Playgroud)