0
我想提醒英文文本,而不是數字,並寫了jQuery代碼返回<span>
s沒有rtl
屬性,但我的問題是它警告兩次數字和英文文本。選擇文本一個具有特定屬性的標記
的JavaScript
$(document).ready(function() {
var text = $("span:not([dir=rtl])").text();
alert(text);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="content">
<h2>Blessing upon the Bearers of the Throne</h2>
<button id="btn">Click</button>
<p style="text-align:center"> </p>
<p style="text-align:center">
<span style="font-size11pt">
<span style="font-family:Calibri,sans-serif">O God, as for the Bearers of Thy Throne, who never flag in glorifying Thee, </span>
</span>
</p>
<p style="text-align:center">
<span style="font-size11pt">
<span style="font-family:Calibri,sans-serif">
<span dir="rtl" lang="AR-SA" style="font-family"Arial","sans-serif"">111111111111111111111111111َ </span>
</span>
</span>
</p>
</div>
也許你只需要選擇最裏面的跨度沒有這個屬性,但當前的選擇也選擇父跨度。你有沒有嘗試類似'span:not([dir =「rtl」]):not(:has(span)'? –
@IlyaStreltsyn does not work can you write more clear and correct code? – sepehr
這是一個jsfiddle:https: //jsfiddle.net/cb69m3e9/(抱歉以前的錯字,從平板電腦中鍵入,似乎自動糾錯會破壞它) –