0

私のphpプロジェクトには、次のhtmlコンテンツを含む「addText」というJavaScript変数があります。

<div class="foxcontainer" style="width:100% !important;">
<h2>FREE IN HOME CONSULTATION</h2>

<ul class="fox_messages">
    <li>Invalid field: Your name</li>
    <li>Invalid field: Your email</li>
</ul>

<form enctype="multipart/form-data" class="foxform" action="/hima/bigriglawgroup/index.php/about-us#mid_131" method="post">
<!-- mod_foxcontact 2.0.19 GNU/GPLv3 -->
<div class="foxfield">
    <input class="invalidfoxtext" value="Your name" title="Your name" style="width:85% !important;display:block;float:none;margin:0 auto !important;" name="_c31f7a92d344f9a5c23d07fd438ba0b6" onfocus="if(this.value==this.title) this.value='';" onblur="if(this.value=='') this.value=this.title;" type="text"> 
    <span class="asterisk"></span>
</div>
<div class="foxfield">
    <input class="invalidfoxtext" value="Your email" title="Your email" style="width:85% !important;display:block;float:none;margin:0 auto !important;" name="_4fd8a7bb907c63baca708086b63eb7f0" onfocus="if(this.value==this.title) this.value='';" onblur="if(this.value=='') this.value=this.title;" type="text"> 
    <span class="asterisk"></span>
</div>
<div class="foxfield">
    <input class="validfoxtext" value="Phone number" title="Phone number" style="width:85% !important;display:block;float:none;margin:0 auto !important;" name="_68a05eb930e9ce854ed0c2d2d25c14a1" onfocus="if(this.value==this.title) this.value='';" onblur="if(this.value=='') this.value=this.title;" type="text">
</div>
<div class="foxfield">
    <textarea rows="" cols="" class="validfoxtext" name="_0ef408e84316ef5737db72a727579f48" title="Notes" style="width:85% !important;height:180px !important;display:block;float:none;margin:0 auto !important;" onfocus="if(this.value==this.title) this.value='';" onblur="if(this.value=='') this.value=this.title;">retret ret ret ret</textarea>
</div>
<div class="foxfield">
    <button class="foxbutton" type="submit" style="margin-right:32px;" name="mid_131">
    <span>Submit</span>
    </button>
</div>
<div class="fox-copyright" style="padding:10px 0 !important;text-indent:0 !important">
    <a target="_blank" title="Joomla contact form" href="#" style="display: none !important; display: inline !important; font-size:10px !important;">powered  by fox contact</a>
</div>

</form>

</div>

ここで、文字列「無効なフィールド」がそのコンテンツに存在するかどうかを確認したいと思います。存在しない場合は、他の機能を実行したいのですが、これを行う方法がわかりません

誰かがこれを知っていますか?ASPSを手伝ってください。

前もって感謝します

4

3 に答える 3

1
if (addText.indexOf("Invalid field") != -1) { /* it's present */ }

// OR with regex

if (/Invalid field/.test(addText)) { /* it's present */ }

// OR with case-insensitve regex:

if (/Invalid field/i.test(addText)) { /* it's present */ }
于 2012-11-30T11:33:01.347 に答える
0

正規表現を使用してhtmlを解析することはお勧めしませんが、バニラJavaScriptで簡単な方法はありません。
jQueryを使用する場合、これは:containsセレクターを使用した非常に簡単なタスクです。

var toSearch = "Invalid field"
    elements = $(':contains('+ toSearch +')');

// if we have any elements that contain the searched keywords
if(elements.length) {
    // do smth
}
于 2012-11-30T11:44:13.940 に答える
0

使用できますstrstr、ドキュメント@ http://www.php.net/manual/en/function.strstr.php

ありがとう

于 2012-11-30T11:33:37.483 に答える