你需要做的是从getContent()
呼叫作为解析返回的字符串HTML!正如你用jQuery标记了你的文章,我假设为此需要使用jQuery。随着中说,你解决你的TincyMCE选择内检索a
元素的href
值,请执行下列操作:
// This value of var selectionFromTinyMCE is an example
// of what parent.tinyMCE.activeEditor.selection.getContent(); returns to you
var selectionFromTinyMCE = 'sit our <a href="../forum/index.php">community forum</a>! We also';
// Here we take the string returned by TinyMCE, wrap it with a span tag,
// and pass it into a jQuery. This forces jQuery to evaluate the string as HTML!
var $jStr = $("<span>"+selectionFromTinyMCE+"</span>");
// You then create new variable and store the value of the href attribute
// of the <a> element from within your string.
var hrefValueFromTinyMCEselection = $jStr.find("a").attr("href");
// Check the console to see the result below, outputted as a string
console.log(hrefValueFromTinyMCEselection);
下面的代码的的jsfiddle版本上面看到它发生现场(开控制台查看结果记录):http://jsfiddle.net/lasha/NF9V8/
你能显示一个实际的字符串,它被存储为你的'selection'变量吗?我想看看TinyMCE用'.getContents()'函数调用实际返回的结果。我可能有一个解决方案为你准备... – Lasha
其实,我已经想通了。很快回答。 :) – Lasha