为什么不使用HTML代码? [英] why not working the html code?
本文介绍了为什么不使用HTML代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
获得一个单击词的句子,如下面的链接所示。
http://jsfiddle.net/HKHGQ/129/ [ ^ ]
但是,当我将代码复制到html文件时,如下所示获取错误。不工作。
Hi,
get the Sentence of a Clicked Word as in the below link.
http://jsfiddle.net/HKHGQ/129/[^]
but, when i copy the code to a html file as below getting error. not working.
<html>
<head>
<script src="jquery-1.8.3.js" language="javascript" type="text/javascript"></script>
<script>
function test()
{
$('p').each(function() {
$(this).html($(this).text().split(/([\.\?!])(?= )/).map(
function(v){return '<span class=sentence1>'+v+'</span>'}
));
});
$('.sentence1').on('click', function() {
//$('#result').text($(this).text());
});
}
</script>
</head>
<body onload="test()">
<p>This is a test paragraph! I love cats. Dogs are fine too... Here's a number : 3.4. Please apply here</p>
</body>
</html>
错误来自以下代码的一部分。
the error getting at the below part of code.
$(this).html($(this).text().split(/([\.\?!])(?= )/).map(
function(v){return '<span class=sentence1>'+v+'</span>'}
));
错误:对象不支持此属性或方法
Error: Object doesn't support this property or method
推荐答案
(' p')。each( function (){
('p').each(function() {
( this )。html(
( this )。text()。spli t(/([\.\?!])(?=)/)。map(
function (v){返回 ' < span class = sentence1>' + v + ' < / span>'}
));
});
(this).text().split(/([\.\?!])(?= )/).map( function(v){return '<span class=sentence1>'+v+'</span>'} )); });
这篇关于为什么不使用HTML代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文