2

わかりました、私はこのコードを持っています

var text = $('.css .cont_code code');
 text.contents().text(function() {
   $(this).each(function() {
   var cssC = "background , background-color , width , height , float , margin , margin-left , margin-right , margin-top , margin-bottom , contents , border , !important"
  if (text === "cssC")
 { 
  $(this).wrap('<span class="stylesC" />');
  }
})
})

コードで提供しているテキストではなく、すべてのテキストノード行var cssC =を取得します。jQueryでtextNodesを取得したことはなく、実際のjavascriptの書き方についてほとんど知りgetElementByIdません実を言うと。

基本的に私がやろうとしているのは、var cssC に配置した特定のテキスト フィールドを取得することですspan class="stylesC" />

http://jsfiddle.net/yzpCE/

4

1 に答える 1

3

http://jsfiddle.net/YxjnR/1/

ここでは多くのjQuery作業を行う必要はありませんがcssC、同じ文字列がスパンでラップされている単語を見つけたら、単語を分割してhtml文字列を置き換えるだけです。

html.replace(new RegExp(this, 'g'), '<span class="stylesC">' + this + '</span>');
于 2013-01-17T06:08:14.153 に答える