2011-12-09 51 views
0

我有了这个跨度:无法更改跨度内容

<span id="inicial"></span> 

和这个JavaScript点击一个按钮里面:

var pat = /\/\S+\//i; 
    context = ''; 
    context = $('#cmd').attr('value'); 
    context= context.match(pat); 
alert(context); //this gives correctly the string i need  
if (context.length){ 
    $('#inicial').text(context); //but it fails to change the text inside the span 
    } 

可能是什么问题呢?

另外我注意到它影响了整个点击功能,它只是停止工作。可能是什么原因?

回答

0

尝试 - 市价修改@Jonathan中号 答案

$('#inicial').html(context[0]); 
+0

在这种情况下,OP的'的.text()'是有效的,而且你并不真的需要实例化一个'新字符串对象。 –

+0

@罗素迪亚斯 - 它被删除,但我认为它可能是它的对象,它引起问题和使用新的字符串.... –