Skip to content

Instantly share code, notes, and snippets.

@tingwei628
Last active August 29, 2015 14:22
Show Gist options
  • Save tingwei628/36c72d7778026957c6c4 to your computer and use it in GitHub Desktop.
Save tingwei628/36c72d7778026957c6c4 to your computer and use it in GitHub Desktop.
[JavaScript] Checked html-like string
/*
例如 Content = '<div style="background-color: rgba(255, 255, 255, 0.843137);">&nbsp; gg<br>yy<br><br><br>uu<br><br>  ff&nbsp;<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);">&nbsp; 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