为什么这不起作用?
$(document).ready(function(){
var content = '<a href="http://example.com/index.php><b>Some text!</b></a> - <a href="http://example.com/index.php" class="ot-origin-anchor">News</a>';
$("#test").replaceWith(function(){
return content;
});
//Here is the problem. I don't know why but I can't define adres.
var adres = $("#test .ot-origin-anchor").attr("href");
//find example.com - ugly :P
var adresRegExp = adres.match(/(\w+:\/\/+(www.|))([^/]+)/);
alert(RegExp.$3);
});
</script>
<div id="test">bnb</div>
Run Code Online (Sandbox Code Playgroud)
.replaceWith()通话结束后,页面上没有带ID的元素test.看起来你打算使用.html()或.append()代替.replaceWith().
var content = '<a href="http://example.com/index.php><b>Some text!</b></a> - <a href="http://example.com/index.php" class="ot-origin-anchor">News</a>';
$("#test").html(content);
// or
$("#test").append(content);
var adres = $("#test .ot-origin-anchor").attr("href");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
197 次 |
| 最近记录: |