Last active
August 29, 2015 14:22
-
-
Save tingwei628/36c72d7778026957c6c4 to your computer and use it in GitHub Desktop.
[JavaScript] Checked html-like string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
例如 Content = '<div style="background-color: rgba(255, 255, 255, 0.843137);"> gg<br>yy<br><br><br>uu<br><br> ff <br> u<br></div><div style="background-color: rgba(255, 255, 255, 0.843137);"><br></div><div style="background-color: rgba(255, 255, 255, 0.843137);"> i</div> ' | |
此code示範如何將Contne html字串,檢查其有沒有word | |
註: var str="我是中文字" | |
(/\w|[^\x00-\xff]/ig).test(str); //回傳是true | |
*/ | |
var html = $(Content); //jQuery 將字串轉成html | |
var innertext = null; | |
//檢查內容每一行有無中英文 | |
for (var i = 0 ; i < html.length; i++) { | |
innertext = html[i].innerText.match(/\w|[^\x00-\xff]/ig); | |
if (innertext !== null) { | |
break; | |
} | |
} | |
//if each line is null ,then innertext is null | |
/* | |
注意在頁籤內容部分 | |
if (languages.length > 1) { //多語系 | |
html = $('<div>'+ values.Content[0] + '</div>'); | |
} | |
else { | |
html = $('<div>' + values.Content + '</div>'); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment