внутренний Html в строку получить indexOf (подстановочный знак) возможно ли это? - PullRequest
0 голосов
/ 25 мая 2020

У меня есть HTML элемент <tmp></tmp> внутри родительского контейнера.

В своей функции я использую глобальную переменную divText, которая является parentContainer.html().toString();

Я хочу избежать возврата к DOM и использовать переданную глобальную переменную divText для определения если элемент HTML "tmp" содержит только один символ (любой один символ);

Если я хочу увидеть, пуст ли элемент tmp, я использую:

if(divText.indexOf('<tmp></tmp>') > -1){
/*I know the tmp container is Empty and exists*/
}

Есть ли такая функция, чтобы определить, содержит ли элемент tmp один символ, например:

if(divText.indexOf('<tmp>(wildcard for any one char)</tmp>') > -1){
/*So i can know if the tmp container contains one character of any kind including space*/
}

Существует ли такая функция?

1 Ответ

0 голосов
/ 25 мая 2020

хорошо, я понял: даже проще, чем я думал.

/*duplicate the divText into variable test*/
var test = divText;
/*use regext to replace the temp container and contents with nothing*/
var test = test.replace(/<tmp>(.*)<\/tmp>/, '');
/*Here we check the length of the original divText with the test string to see if    it matches the characters for <tmp>(5) + </tmp>(6) + 1(for contents) ofcourse if you ever need something like this you can increase the one to what ever count you want*/
if((divText.length - test.length) == 12){
/*Here if there is one character inside do what ever*/
func.clearTimers('move');
func.showHide(0);
return;
}

я доволен этим.

...