草庐IT

javascript - jQuery 在 iframe 的顶部/主窗口中隐藏/访问元素

coder 2024-07-24 原文

我使用的是 CRM 系统,我无法控制系统生成的 HTML。这是我正在处理的 HTML 标记的最简单形式。

<button id="cmdedit">Edit</button>
<textarea cols="30" rows="10"> Hi there </textarea>
<iframe src="s_blank.html" frameborder="0"></iframe>

我想隐藏cmdedit <button>页面加载后。我只能更改那个 <textarea> 的内容然后将其作为以下 <iframe> 的 HTML 内容插入到 DOM 中在页面加载上。我可以包括 <script>标记并编写进入该 <iframe> 的 javascript 或 Jquery 语句并且 javascript 警报语句工作得很好。我试图隐藏 <button>使用以下代码,但在页面加载后都不起作用。

iframe 内的脚本:

<script type="text/javascript">
     $(document).ready(function(){         
        var MyRoleList = "@me.rolelist@";
        if (MyRoleList.indexOf(",9875,") > -1){         
            alert('aaa');   
            $('#cmdedit').hide();     
        }
     });
  </script>

系统生成完整的 HTML:

<html lang="en"><head>
    <title>Examinee Notice</title>
    <link rel="icon" type="image/x-icon" href="/images/favicon.ico">
	<link rel="SHORTCUT ICON" href="/images/favicon.ico">
	<link rel="stylesheet" type="text/css" href="/css/ccss/styles_common_basic_404048.css?version=201711.05">

    <link rel="stylesheet" type="text/css" media="screen" href="/jquery/jquery-confirm-master/css/jquery-confirm.css?v=201711.05">
    <script language="JavaScript" src="/jquery/jquery.js?v=201711.05"></script><style></style>
    <script type="text/javascript" src="/jquery/jquery-confirm-master/dist/jquery-confirm.min.js?v=201711.05"></script>
    <script type="text/javascript" language="JavaScript" src="/Ajax/uta/uta.js?v=201711.05"></script>
    <script type="text/javascript" language="JavaScript" src="/js/ssvalidate.js?v=201711.05"></script>
    <script type="text/javascript" src="/js/ssfieldfunctions.js?v=201711.05"></script>
    <script type="text/javascript" src="/js/ssfunctions.js?v=201711.05"></script>
    <script language="javascript">
        var _iseditmode=false;
            function jqueryalert(msg, confirmfn) {
                $.confirm({
                    title: "Hey Muhammad",
                    content: msg,
                    icon: 'fa fa-exclamation-triangle',
                    theme: 'material',
                    animation: 'scale',
                    closeAnimation: 'scale',
                    type: 'orange',
                    buttons: {
                        confirm: {
                            text: "OK",
                            btnClass: 'btn-orange',
                            keys: ['enter'],
                            action: function() {
                                if (confirmfn) {
                                    confirmfn();
                                }
                            }
                        }
                    }
                });
            }
            function jqueryconfirm(msg, confirmfn, cancelfn) {
                $.confirm({
                    title: "Hey Muhammad",
                    content: msg,
                    icon: 'fa fa-exclamation-triangle',
                    theme: 'material',
                    animation: 'scale',
                    closeAnimation: 'scale',
                    type: 'orange',
                    buttons: {
                        confirm: {
                            text: "Yes",
                            btnClass: 'btn-orange',
                            action: function() {
                                if (confirmfn) {
                                    confirmfn();
                                }
                            }
                        },
                        cancel: {
                            text: "No",
                            action: function() {
                                if (cancelfn) {
                                    cancelfn();
                                }
                            }
                        }
                    }
                });
            }
            function jqueryprompt(msg, confirmfn, cancelfn) {
                $.confirm({
                    title: "Hey Muhammad",
                    content: msg,
                    icon: 'fa fa-exclamation-triangle',
                    theme: 'material',
                    animation: 'scale',
                    closeAnimation: 'scale',
                    type: 'orange',
                    buttons: {
                        confirm: {
                            text: "Continue",
                            btnClass: 'btn-orange',
                            keys: ['enter'],
                            action: function() {
                                if (confirmfn) {
                                    if (!confirmfn(this.$content)) {
                                        return false;
                                    }
                                }
                            }
                        },
                        cancel: {
                            text: "Cancel",
                            keys: ['esc'],
                            action: function() {
                                if (cancelfn) {
                                    cancelfn();
                                }
                            }
                        }
                    }
                });
            }
        function no_error()
        { return true; }
        //window.onerror=no_error;

        function getsrc()
        { var frm=window.frames["page_win"].document.forms[0];
            if(frm==null) return "";
            var valuestr='\n var frm_inp=document.forms[0];\n';
            var ctltype;
            for (var i=0;i<frm.elements.length;i++)
            { ctltype=frm.elements[i].type.toLowerCase();
                if(ctltype=='radio'||ctltype=='checkbox')
                { if (frm.elements[i].checked)
                        valuestr+='\nfrm_inp.elements['+i+'].checked=true;';
                }
                else
                    valuestr+='\nfrm_inp.elements['+i+'].value=decodeURIComponent("'+encodeURIComponent(frm.elements[i].value)+'");';
            }

            return valuestr;
        }



        function puttxt()
        {
            window.frames["page_win"].document.writeln(document.frmtext.txt.value);
            window.frames["page_win"].document.close();
            var cmd=document.getElementById('cmdprint');
            if(cmd!=null)
                cmd.style.display="inline";
            cmd=document.getElementById('cmdemail');
            if(cmd!=null)
                cmd.style.display="inline";
            cmd=document.getElementById('cmdpdf');
            if(cmd!=null)
                cmd.style.display="inline";
            
            cmd=document.getElementById('cmddocx');
            if(cmd!=null)
                cmd.style.display="inline";
            
            cmd=document.getElementById('cmdemailpdf');
            if(cmd!=null)
                cmd.style.display="inline";
            cmd=document.getElementById('cmdemaildoc');
            if(cmd!=null)
                cmd.style.display="inline";
            if (window.frames["page_win"]!=null && window.frames["page_win"].ss_load)
                window.frames["page_win"].ss_load();
            if(window.frames["page_win"]!=null)window.frames["page_win"].focus();
        }

        function editdoc(button)
        {
            if(!_iseditmode)
            {window.frames["page_win"].location.href='/s_editor.html';
                button.value="Preview";



                _iseditmode=true;
            }else
            {  document.frmtext.txt.value=window.frames["page_win"].oCKeditor.getData();

                window.frames["page_win"].document.writeln(document.frmtext.txt.value);
                window.frames["page_win"].document.close();
                button.value="Edit";
                _iseditmode=false;
            }

            switchbut(button.form,'cmdprint');
            switchbut(button.form,'cmdnewin');
            switchbut(button.form,'cmdemail');
            switchbut(button.form,'cmdemailpdf');
            switchbut(button.form,'cmdemaildoc');
            switchbut(button.form,'cmdpdf');
            switchbut(button.form,'cmdsavehtml');
            switchbut(button.form,'cmdsavepdf');
            switchbut(button.form,'cmdsavedoc');
            if ($('#functable').css("display") == "none")
                $('#functable').css("display", "table");
            else
                $('#functable').css("display", "none");
        }

        function switchbut(frm ,ctl)
        { var octl =frm.elements[ctl];
            if (octl!=null)
            {
                octl.disabled=!octl.disabled;
                if (octl.disabled)
                    $('[name="'+ctl+'"]').css("display", "none");
                else
                    $('[name="'+ctl+'"]').css("display", "inline");
            }
        }
        function CheckIsIE()
        {
            return (navigator.appName.toUpperCase().indexOf('MICROSOFT')>-1) ;

        }


        function printdoc()
        {

            if (CheckIsIE() == true)
            {
                document.page_win.focus();
                document.page_win.print();
            }
            else
            {
                window.frames['page_win'].focus();
                window.frames['page_win'].print();
            }

        }

        function savelocal(fname)
        {
            window.frames["page_win"].document.execCommand('SaveAs',null,fname)
        }


        function saveserver(type)
        { 
            if(_iseditmode) {
                document.frmtext.txt.value=window.frames["page_win"].oCKeditor.getData();
            }
            var frm=document.frmtext;
            frm.filename.value=frm.filename.value.replace(/\.html/,"");
            frm.filename.value=frm.filename.value.replace(/\.pdf/,"");

            if(frm.mfolderid.value=='') {
                alert("Please select a folder name to save to.");
                return false;
            }
            
            var html = "<div class=\"form-group\" style=\"text-align:center\"><div style=\"margin:5px\">Please enter a file name.</div><input class=\"Large\" type=\"text\" placeholder=\"File Name\" class=\"form-control\" id=\"filenameprompt\" value=\"" + frm.filename.value + "\"/></div>";
            jqueryprompt(html, function(promptobj) {
                var frm = document.frmtext;
                var newf = promptobj.find("#filenameprompt").val();
                if (newf == '') {
                    alert("File name cannot be empty.");
                    return false;
                } else if (!isValidFileName(newf)) {
                    alert("File name contains invalid characters (;,#,=,?)");
                    return false;
                }
                frm.filename.value=newf.replace(/\s|\/|\\/g,'_');
                saveserversb(type)
                return true;
            });
            
        }
        function saveserversb(type) {
            
            saveserversb2(type);
            
        }
        function saveserversb2(type) {
            var frm=document.frmtext;
            var id=frm.mfolderid.value;
            if (id.indexOf('-')>0) {
                frm.objectid.value=id.substring(0,id.indexOf('-'));
                frm.folderid.value=id.substring(id.indexOf('-')+1);
            } else {
                frm.folderid.value=frm.mfolderid.value;
            }
            frm.action='s_savetextfile.jsp?type='+type;
            frm.target='page_win';
            frm.submit();
        }
    function newwind(frm)
    { var src;
        if(_iseditmode)
            src=window.frames["page_win"].oCKeditor.getData();
        else
            src=frm.txt.value;

        OpenWindow=window.open("", "newwin", "menubar=yes,scrollbars=yes,width=550,height=300,status=no,resizable=yes,dependent=yes,alwaysRaised=yes");
        OpenWindow.document.write(src);
        OpenWindow.document.close()
    }

    function newwinda()
    {
        var frm = document.frmtext;
        var inf = frm.txt.value;
        win = window.open("", "newwina", "menubar=yes,scrollbars=yes,width=650,height=500,status=no,resizable=yes,dependent=yes,alwaysRaised=no");
        win.document.write("" + inf + "");
        win.document.close();
    }

    function gotohcai()
    {   alert('When submitting to HCAI, please be aware that the submission time frame can vary between 0-120 min. If your submission is surpassing this time frame, please notify SmartSimple Support.', function() {
            location.href="/Apps/Bridge/hc_submissions.jsp?fieldid=1274403&entity=24&objectid=1127956&appid=102946";
        });
    }
    function gotosignority() {
        showsave("Load in Progress");
        location.href="/Apps/Bridge/sg_signority.jsp?fieldid=1274403&entity=24&objectid=1127956&appid=102946&codedid=QHJrJ0keIhgKFlALJGc1KgRXEAcuXRsTH2JcU0VNZl8~&islb=0&exportpdf=0&ismwin=0";
    }



        function emailpdf() {
            if(_iseditmode)
                document.frmtext.txt.value=window.frames["page_win"].oCKeditor.getData();

            var frm=document.frmtext;
            frm.body.value=frm.txt.value;

            
            emailpdfsb();
            
        }
        function emailpdfsb() {
            var frm=document.frmtext;
            window.open("", "comp_win", "menubar=yes,scrollbars=yes,width=550,height=300,status=no,resizable=yes,dependent=yes,alwaysRaised=yes");
            frm.action="/Comm/ms_makepdf.jsp";
            frm.target='comp_win';
            frm.submit();
        }

    function pdfwrite(frm)
    {if(_iseditmode)
            document.frmtext.txt.value=window.frames["page_win"].oCKeditor.getData();

        var frm=document.frmtext;
        new_win = window.open('','new_win', 'menubar=no,scrollbars=yes,width=600,height=340,status=no,resizable=yes,top=200,left=200,dependent=yes,alwaysRaised=yes');
        new_win.opener = window;
        new_win.focus();

        frm.body.value=frm.txt.value;
        frm.action="/pdfWriter";
        frm.target='new_win';
        frm.submit();
    }
    function docxwrite(frm)
    {if(_iseditmode)
            document.frmtext.txt.value=window.frames["page_win"].oCKeditor.getData();

        var frm=document.frmtext;
        new_win = window.open('','new_win', 'menubar=no,scrollbars=yes,width=600,height=340,status=no,resizable=yes,top=200,left=200,dependent=yes,alwaysRaised=yes');
        new_win.opener = window;
        new_win.focus();

        frm.body.value=frm.txt.value;
        frm.action="/docxWriter";
        
        frm.submit();
    }

    function showconv()
    {
        document.getElementById("saveinprogress").style.display="block";
        document.getElementById("sip").src="/images/saveinprogress.gif";
    }

    function switchlang(lang) {
        var url=location.href;
        if (url.indexOf("cmdlang")>-1)
            url=url.substring(0,url.indexOf("cmdlang"));
        url+="&cmdlang="+lang;
        location.href=url;
    }


    function gohtml(){
        if(_iseditmode)
            document.frmtext.txt.value=window.frames["page_win"].oCKeditor.getData();
        var frm=document.frmtext;
        var jsrc=getsrc();
        if(jsrc.length>0)
            frm.txt.value+="\<script language=javascript\>"+jsrc+"\</script\>";
        frm.body.value=frm.txt.value;
        frm.iswebpage.value="1";
        popupNote();
        frm.action="/s_viewpagehtml.jsp";
        frm.target='comp_win';
        window.open("", "comp_win", "menubar=yes,scrollbars=yes,width=736,height=700,status=no,resizable=yes,dependent=yes,alwaysRaised=yes");
        frm.submit();
        self.close();
    }

    function popupNote(){
        alert("Right click the new popup page and \"Save as\" a HTML file.");
    }

    function setfrmheight() {
		
        $("#page_win").height($("body").height() - ($("#header").height()));
    }

    </script>
    <script type="text/javascript" src="/js/ssfunctions.js?v=201711.05"></script>

    <style>
        html,body{
            height:100%;
            overflow: hidden;
        }
        body{
            min-width:100%;
            max-width:100%;
            width:100%;
        }
    </style>
</head>
<body scroll="no" onload="puttxt();setfrmheight();" onresize="setfrmheight();">

    <!--<div style="display:none;width:100%;height:100%;top:0;left:0;position:absolute;background:#FFFFFF;z-Index:200;opacity:0.8;filter:alpha(opacity=80);text-align:center" id="saveinprogress"><table height="100%" width="100%" cellspacing="0" cellpadding="0"><tr><td valign="middle" align="center"><img src='/images/blank.gif' id="sip"><br><strong style='font-size:16pt;color:#697F39'>PDF Creation in Progress</strong><br><strong style='font-size:12pt;color:#697F39'>Please Wait</strong></td></tr></table></div>-->
    <div style="display:none;width:100%;height:100%;top:0;left:0;position:absolute;background:#FFFFFF;z-Index:200;opacity:0.8;filter:alpha(opacity=80);text-align:center" id="saveinprogress"><table width="100%" height="100%" cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle" align="center"><img src="/images/blank.gif" id="sip" alt="Save In Progress"><br><div style="font-size:16pt;font-weight:bold;color:#697F39" id="smsg">PDF Creation in Progress</div><br><strong style="font-size:12pt;color:#697F39">Please Wait</strong></td></tr></tbody></table></div>


    <div id="header">
        
        
        <table width="100%" cellspacing="0" cellpadding="0" border="0">
            <tbody><tr>
                <th class="Title">Web Page View Actions</th>
            </tr>
        </tbody></table>
        
        <form name="frmtext" target="page_win" action="s_savetextfile.jsp" method="POST">
        <input name="ss_formtoken" id="ss_formtoken" value="0A0133DEE42C7A11D0AA8C8988695CEDAA905422B38099B3C0C9B463CEDC7663" type="hidden">
        <input value="1127956" name="objectid" type="hidden">
        <input value="" name="folderid" type="hidden">
        <input value="0" name="peopleid" type="hidden">
        <input value="0" name="varcontactid" type="hidden">
        <input value="2" name="format" type="hidden">
        <input value="" name="pswd" type="hidden">
        <input value="1" name="peopletypeid" type="hidden">
        <input value="1" name="iswebpage" type="hidden">
        <input value="" name="body" type="hidden">
        <input value="" name="subject" type="hidden">
        <input value="" name="cc" type="hidden">
        <input value="0" name="touser" type="hidden">
        <input value="0" name="maxp" type="hidden">
        <input value="Examinee_Notice_1127956" name="pdfname" type="hidden">
        <input value="Examinee_Notice_1127956" name="filename" type="hidden">
        <input value="24" name="entity" type="hidden">
        <input value="102946" name="appid" type="hidden">
        
        <table width="100%" cellspacing="0" cellpadding="0" border="0">
            <tbody><tr>
                <td class="Title">

                    <table cellspacing="0" cellpadding="0" border="0">
                        <tbody><tr>
                            <td colspan="3">

                                
                                <input name="cmdedit" id="cmdedit" class="ButtonSm" value="Edit" onclick="editdoc(this)" type="button">
                                
                                <input name="cmdemailpdf" id="cmdemailpdf" style="display: inline;" class="ButtonSm" value="Email as PDF" onclick="emailpdf()" type="button">
                                
                                <input name="cmdpdf" id="cmdpdf" style="display: inline;" class="ButtonSm" value="Export as PDF" onclick="pdfwrite();" type="button">
                                

                            </td>
                        </tr>
                    </tbody></table>

                </td>
            </tr>
        </tbody></table>
        
        
        <table id="functable" name="functable" width="100%" cellspacing="0" cellpadding="0" border="0">
            <tbody><tr>
                <td class="Title">

                    <div style="float:right;padding:4px 4px 0 0">
                        
                        Folder Name: <select name="mfolderid" class="AppNav" style="max-width:300px"><option value=""> --Select a folder-- </option><option value="1267619">Active Drafts</option>
<option value="1267614">Active Medical File</option>
<option value="1269758">Adjuster Service Requests (ARF - Portal)</option>
<option value="1267610" selected="">Adjuster, Assessor, Examinee And Legal Rep Communications</option>
<option value="1267616">Archived Medical File</option>
<option value="1274156">Client Invoices</option>
<option value="1269519">Correspondence - Notice to Assessor forms &amp; Assessment Plans</option>
<option value="1267612">Correspondence - Other</option>
<option value="1267620">Final Reports</option>
<option value="1267615">IME Guidelines Kits</option>
<option value="1267621">Informed Consent</option>
<option value="1267623">Provider Invoices</option>
<option value="1269372">Invoices and Consents</option>
<option value="1269448">Medical Briefs and Insurer Examination Reports</option>
<option value="1273039">Previous Drafts</option>
<option value="1267609">Production and Court Prep</option>
<option value="1273836">Referral Mandate</option>
</select>

                        
                    </div>


                    
                    <input name="cmdsavepdf" class="Button" value="Save To Server as PDF" onclick="saveserver(1)" type="button">
                    



                </td>
            </tr>
        </tbody></table>
        

        <textarea cols="0" rows="0" name="txt" style="display:none">
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
   &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
      &lt;title&gt;Claimant Notice&lt;/title&gt;
      &lt;style type="text/css"&gt;		
         Table td 
         {
         padding: 3px;  
         vertical-align: top;
         }
         body
         {
         font-size:10pt;font-family:arial;				
         }
      &lt;/style&gt;
      &lt;script language="JavaScript" src="/jquery/jquery.js?v=201711.05"&gt;&lt;/script&gt;
      &lt;style&gt;&lt;/style&gt;
      &lt;script type="text/javascript"&gt;
         $(document).ready(function(){                      
         alert('aaa');   
        $('#cmdedit').hide();   
         	}
         });
      &lt;/script&gt;
   &lt;/head&gt;

   &lt;body&gt;
      &lt;table width="700px" border="0" align="center" cellpadding="0" cellspacing="0"&gt;
         &lt;tbody&gt;
            &lt;tr&gt;
               &lt;td&gt;                    
                  Test Test						
               &lt;/td&gt;
            &lt;/tr&gt;
         &lt;/tbody&gt;
      &lt;/table&gt;
   &lt;/body&gt;
&lt;/html&gt;</textarea>

    </form>
    </div>
      <div class="iframe_ipad">
    <iframe src="/s_blank.html" id="page_win" name="page_win" style="height: 71px;" width="100%" frameborder="0"></iframe>
      </div>




</body></html>

最佳答案

您正试图隐藏 ID 为 cmdedit 的元素来自在 <iframe> 中执行的 javascript 代码.但是元素不在里面 <iframe>所以 jQuery 找不到它。

您需要告诉 jQuery 去哪里寻找元素。您可以通过将第二个参数传递给 jQuery 选择器来实现。来自 jQuery Api documentation page :

jQuery( selector [, context ] )

selector
Type: Selector
A string containing a selector expression

context
Type: Element or jQuery
A DOM Element, Document, or jQuery to use as context
-

所以只需要通过top windowdocument对象来选择要隐藏的元素即可。

    $(function(){
        $("#cmdedit", window.top.document).hide()
    });

Or you can use the jQuery of the main window

window.top.$("#cmdedit").hide();

Or you can use plain javascript

window.top.document.getElementById('cmdedit').style.display = 'none';

关于javascript - jQuery 在 iframe 的顶部/主窗口中隐藏/访问元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48671136/

有关javascript - jQuery 在 iframe 的顶部/主窗口中隐藏/访问元素的更多相关文章

  1. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  2. ruby-on-rails - 在混合/模块中覆盖模型的属性访问器 - 2

    我有一个包含模块的模型。我想在模块中覆盖模型的访问器方法。例如:classBlah这显然行不通。有什么想法可以实现吗? 最佳答案 您的代码看起来是正确的。我们正在毫无困难地使用这个确切的模式。如果我没记错的话,Rails使用#method_missing作为属性setter,因此您的模块将优先,阻止ActiveRecord的setter。如果您正在使用ActiveSupport::Concern(参见thisblogpost),那么您的实例方法需要进入一个特殊的模块:classBlah

  3. ruby - 续集在添加关联时访问many_to_many连接表 - 2

    我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以

  4. jquery - 我的 jquery AJAX POST 请求无需发送 Authenticity Token (Rails) - 2

    rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送

  5. ruby - 在哈希的键数组中追加元素 - 2

    查看我的Ruby代码:h=Hash.new([])h[0]=:word1h[1]=h[1]输出是:Hash={0=>:word1,1=>[:word2,:word3],2=>[:word2,:word3]}我希望有Hash={0=>:word1,1=>[:word2],2=>[:word3]}为什么要附加第二个哈希元素(数组)?如何将新数组元素附加到第三个哈希元素? 最佳答案 如果您提供单个值作为Hash.new的参数(例如Hash.new([]),完全相同的对象将用作每个缺失键的默认值。这就是您所拥有的,那是你不想要的。您可以改用

  6. 「Python|Selenium|场景案例」如何定位iframe中的元素? - 2

    本文主要介绍在使用Selenium进行自动化测试或者任务时,对于使用了iframe的页面,如何定位iframe中的元素文章目录场景描述解决方案具体代码场景描述当我们在使用Selenium进行自动化测试的时候,可能会遇到一些界面或者窗体是使用HTML的iframe标签进行承载的。对于iframe中的标签,如果直接查找是无法找到的,会抛出没有找到元素的异常。比如近在咫尺的例子就是,CSDN的登录窗体就是使用的iframe,大家可以尝试通过F12开发者模式查看到的tag_name,class_name,id或者xpath来定位中的页面元素,会抛出NoSuchElementException异常。解决

  7. ruby - Hanami link_to 助手只呈现最后一个元素 - 2

    我是HanamiWorld的新人。我已经写了这段代码:moduleWeb::Views::HomeclassIndexincludeWeb::ViewincludeHanami::Helpers::HtmlHelperdeftitlehtml.headerdoh1'Testsearchengine',id:'title'hrdiv(id:'test')dolink_to('Home',"/",class:'mnu_orizontal')link_to('About',"/",class:'mnu_orizontal')endendendendend我在模板上调用了title方法。htm

  8. ruby - 有没有办法从 ruby​​ case 语句中访问表达式? - 2

    我想从then子句中访问c​​ase语句表达式,即food="cheese"casefoodwhen"dip"then"carrotsticks"when"cheese"then"#{expr}crackers"else"mayo"end在这种情况下,expr是食物的当前值(value)。在这种情况下,我知道,我可以简单地访问变量food,但是在某些情况下,该值可能无法再访问(array.shift等)。除了将expr移出到局部变量然后访问它之外,是否有直接访问caseexpr值的方法?罗亚附注我知道这个具体示例很简单,只是一个示例场景。 最佳答案

  9. jquery - 如何将 AJAX 变量从 jQuery 传递到他们的 Controller ? - 2

    我有一个电子邮件表格。但是我正在制作一个测试电子邮件表单,用户可以在其中添加一个唯一的电子邮件,并让电子邮件测试将其发送到该特定电子邮件。为了简单起见,我决定让测试电子邮件通过ajax执行,并将整个内容粘贴到另一个电子邮件表单中。我不知道如何将变量从我的HAML发送到我的Controllernew.html.haml-form_tagadmin_email_blast_pathdoSubject%br=text_field_tag'subject',:class=>"mass_email_subject"%brBody%br=text_area_tag'message','',:nam

  10. ruby - 从外部访问类的实例变量 - 2

    我理解(我认为)Ruby中类变量和类的实例变量之间的区别。我想知道如何从该类外部访问该类的实例变量。从内部(即在类方法中而不是实例方法中),它可以直接访问,但是从外部,有没有办法做MyClass.class.[@$#]variablename?我没有任何具体原因要这样做,只是学习Ruby并想知道是否可行。 最佳答案 classMyClass@my_class_instance_var="foo"class上述yield:>>foo我相信Arkku演示了如何从类外部访问类变量(@@),而不是类实例变量(@)。我从这篇文章中提取了上述内

随机推荐