javascript - HTML 按钮操作在 Safari 中不起作用

标签 javascript html internet-explorer safari

但是,我正在 Safar 中运行一个网页;我注意到,当我按下保存按钮时,事件不会触发。不过它在 IE 中运行得很好。我研究了这个问题,发现这不是由于缺少值属性或单/双引号细节造成的。任何帮助,将不胜感激。

<input type='button' name='Save' id='saveCut' value='Save Cut' class=button onClick=\"Puma.saveTheCut()\">

JS函数

Puma.saveTheCut = function () {
    var offerId = inStoreCut.cutOfferFields[0];
    var merchId = inStoreCut.cutOfferFields[1];
    var adId = inStoreCut.cutOfferFields[2];
    var eventID = inStoreCut.cutOfferFields[3]; 
    var adNum = inStoreCut.cutOfferFields[4]; 
    var cutID = inStoreCut.cutOfferFields[5];  


    var merchDescription = parent.main.document.getElementById('merchDescription').value;
    var UPC = parent.main.document.getElementById('merchUPC').value;

    var nrfSampleColorObj = parent.main.document.getElementById('itemColor');
    var nrfSampleColor = nrfSampleColorObj.options[nrfSampleColorObj.selectedIndex].value;

    var nrfsampleSubColorObj = parent.main.document.getElementById('itemChildColor');
    var colorCodeStr = nrfsampleSubColorObj.options[nrfsampleSubColorObj.selectedIndex].value;

    var nrfsampleSubColor = colorCodeStr.substring(0, 3);

    var customer_Facing_Color = parent.main.document.getElementById('merchCustomerFacingColor').value;


    var division = parent.main.document.getElementById('merchFob').value;
    var deptNum = parent.main.document.getElementById('merchDept0~0').value;
    var vendorNum = parent.main.document.getElementById('merchVendorNum0~0').value;
    var pID = parent.main.document.getElementById('pID0~0').value;

    var regPrice = parent.main.document.getElementById('regPrice').value;
    var sampleSize = parent.main.document.getElementById('itemSize').value;
    var itemQty = parent.main.document.getElementById('itemQty').value;
    if (parent.main.document.getElementById('chkMerchSet').checked) {
        var set = "1";
    }
    else {
        var set = "0";
    }

    var sampleTypeObj = parent.main.document.getElementById("itemType");
    var sampleType = sampleTypeObj.options[sampleTypeObj.selectedIndex].text;


    var merchColorCorrObj = parent.main.document.getElementById("merchColorCorr");
    var colorCorr = merchColorCorrObj.options[merchColorCorrObj.selectedIndex].value;
    var merchSwatchObj = parent.main.document.getElementById("merchSwatch");
    var Swatch = merchSwatchObj.options[merchSwatchObj.selectedIndex].value;
    var pantoneColor = parent.main.document.getElementById('merchPantone').value;
    var photoStylingDetails = parent.main.document.getElementById('merchPhotoStylingDetails').value;
    var mCOMSampleId = parent.main.document.getElementById('mCOMSample').value;

    var deptName = parent.main.document.getElementById('merchDeptName0~0').innerHTML;
    var vendorName = Puma.decoder(parent.main.document.getElementById('merchVendorName0~0').innerHTML);

    if (parent.main.document.getElementById('pidStatus0~0').value == "NOT IN PD") {
        var pidStatus = "0";
    }
    else {
        var pidStatus = "1";
    }
    var pidDescription = parent.main.document.getElementById('pidDescription').value;
    var webId = parent.main.document.getElementById('webID0~0').innerHTML;
    var vStyle = parent.main.document.getElementById('merchVStyle').value;
    var markStyle = parent.main.document.getElementById('merchMarkStyle').value;
    var subClass = parent.main.document.getElementById('Subclass').value;
    // var productDescription = parent.main.document.getElementById('productDescription').value;
    var docLineitemNum = parent.main.document.getElementById('merchDoc').value;

    var merchTurnInStatusObj = parent.main.document.getElementById("merchTurnInStatus");
    var turnInStatus = merchTurnInStatusObj.options[merchTurnInStatusObj.selectedIndex].text;
    var reason = parent.main.document.getElementById('merchReason').value;
    var merchCountryOriginObj = parent.main.document.getElementById("countryOfOrigin");
    var countryOfOrigin = merchCountryOriginObj.options[merchCountryOriginObj.selectedIndex].value;
    var importedCountry = parent.main.document.getElementById("importedCountries").value;
    //var importedCountry = merchImportedCountryObj.options[merchImportedCountryObj.selectedIndex].text;
    var fabricContent = parent.main.document.getElementById("fabricContent").value;
    var careInstructions = parent.main.document.getElementById("careInstructions").value;
    var offerDescription = parent.main.document.getElementById("offerDescription").value;
    var onlyAtMacysObj = parent.main.document.getElementById("onlyAtMacys");
    var onlyAtMacysValue = parseInt(onlyAtMacysObj.options[onlyAtMacysObj.selectedIndex].value, 10);
    var onlyAtMacys = onlyAtMacysValue;

    var legalOneObj = parent.main.document.getElementById("legalOne");
    var legalOne = legalOneObj.options[legalOneObj.selectedIndex].value;
    var legalOneExplain = parent.main.document.getElementById("explainLegalOne").value;
    var legalTwoObj = parent.main.document.getElementById("legalTwo");
    var legalTwo = legalTwoObj.options[legalTwoObj.selectedIndex].value;
    var legalTwoExplain = parent.main.document.getElementById("explainLegalTwo").value;
    var legalThreeObj = parent.main.document.getElementById("legalThree");
    var legalThree = legalThreeObj.options[legalThreeObj.selectedIndex].value;
    var legalThreeExplain = parent.main.document.getElementById("explainLegalThree").value;
    var legalFourObj = parent.main.document.getElementById("legalFour");
    var legalFour = legalFourObj.options[legalFourObj.selectedIndex].value;

    var fiftyObj = parent.main.document.getElementById("overFifty");
    var fifty = fiftyObj.options[fiftyObj.selectedIndex].value;
    var userId = parent.botnav.uinfo.userID;

    if (Puma.btiRequiredFieldIsValidated() == true) {
        if (inStoreCut.existingRecord == false) {
            sql = "action=saveMerchFormForCut&cutID=" + cutID +
               //sql = "action=updateMerchFormForCut&cutID=" + cutID +
              "&merchDescription=" + encodeURIComponent(merchDescription) +
              "&UPC=" + UPC +
              "&nrfSampleColor=" + nrfSampleColor +
              "&nrfSampleSubColor=" + nrfsampleSubColor +
              "&division=" + encodeURIComponent(division) +
              "&deptNum=" + deptNum +
              "&merchVendorNum=" + vendorNum +
              "&pID=" + pID +
              "&Customer_Facing_Color=" + encodeURIComponent(customer_Facing_Color) +
              "&regPrice=" + regPrice +
              "&sampleSize=" + encodeURIComponent(sampleSize) +
              "&itemQty=" + itemQty +
              "&set=" + set +
              "&sampleType=" + sampleType +
              "&colorCorr=" + colorCorr +
              "&Swatch=" + Swatch +
              "&pantoneColor=" + encodeURIComponent(pantoneColor) +
              "&photoStylingDetails=" + encodeURIComponent(photoStylingDetails) +
              "&mCOMSampleId=" + mCOMSampleId +
              "&deptName=" + deptName +
              "&vendorName=" + encodeURIComponent(vendorName) +
              "&pidStatus=" + pidStatus +
              "&pidDescription=" + pidDescription +
              "&webId=" + webId +
              "&vStyle=" + vStyle +
              "&markStyle=" + markStyle +
              "&subClass=" + subClass +
              "&docLineItemNum=" + docLineitemNum +
              "&merchTurnInStatus=" + turnInStatus +
              "&reason=" + encodeURIComponent(reason) +
              "&countryOfOrigin=" + countryOfOrigin +
              "&importedCountry=" + importedCountry +
              "&fabricContent=" + encodeURIComponent(fabricContent) +
              "&careInstructions=" + encodeURIComponent(careInstructions) +
              "&offerDescription=" + encodeURIComponent(offerDescription) +
              "&onlyAtMacys=" + onlyAtMacys +
              "&legalOne=" + legalOne +
              "&legalOneExplain=" + legalOneExplain +
              "&legalTwo=" + legalTwo +
              "&legalTwoExplain=" + legalTwoExplain +
              "&legalThree=" + legalThree +
              "&legalThreeExplain=" + legalThree +
              "&legalFour=" + legalFour +
              "&fifty=" + fifty +
              "&createdBy=" + userId

            var ajaxMaster = new AjaxMaster(sql, "Puma.saveMerchFormForCutData(data)", "", "btiDispatcher.aspx");


            sql = "action=updateMerchFormForCut&sql=" + encodeURIComponent(msql);
            objAjaxAd.main_flag = "updateMerchFormForCut";
            objAjaxAd.SendQuery(sql);
            // "[t0].[signedByUserID]," +
            // "[t0].[signedStatus]," +
            //"[t0].[dateSigned]," + 
            //"[t0].[signedLastByUserID]," +
            //"[t0].[dateLastSigned1]," +
            //"[t0].[signedLastStatus]" +


           // var ajaxMaster = new AjaxMaster(sql, "Puma.updateMerchFormForCutData(data)", "", "puma_core.aspx");
        }
        else {
            sql = "action=updateMerchFormForCut&cutID=" + cutID +
             "&offerId" + offerId +
             "&merchId" + merchId +
             "&adID" + adId +
             "&eventID" + eventID +
             "&adNum" + adNum +
             "&merchDescription=" + encodeURIComponent(merchDescription) +
             "&UPC=" + UPC +
             "&nrfSampleColor=" + nrfSampleColor +
             "&nrfSampleSubColor=" + nrfsampleSubColor +
             "&division=" + encodeURIComponent(division) +
             "&deptNum=" + deptNum +
             "&merchVendorNum=" + vendorNum +
             "&pID=" + pID +
             "&Customer_Facing_Color=" + encodeURIComponent(customer_Facing_Color) +
             "&regPrice=" + regPrice +
             "&sampleSize=" + encodeURIComponent(sampleSize) +
             "&itemQty=" + itemQty +
             "&set=" + set +
             "&sampleType=" + sampleType +
             "&colorCorr=" + colorCorr +
             "&Swatch=" + Swatch +
             "&pantoneColor=" + encodeURIComponent(pantoneColor) +
             "&photoStylingDetails=" + encodeURIComponent(photoStylingDetails) +
             "&mCOMSampleId=" + mCOMSampleId +
             "&deptName=" + deptName +
             "&vendorName=" + encodeURIComponent(vendorName) +
             "&pidStatus=" + pidStatus +
             "&pidDescription=" + pidDescription +
             "&webId=" + webId +
             "&vStyle=" + vStyle +
             "&markStyle=" + markStyle +
             "&subClass=" + subClass +
             "&docLineItemNum=" + docLineitemNum +
             "&merchTurnInStatus=" + turnInStatus +
             "&reason=" + encodeURIComponent(reason) +
             "&countryOfOrigin=" + countryOfOrigin +
             "&importedCountry=" + importedCountry +
             "&fabricContent=" + encodeURIComponent(fabricContent) +
             "&careInstructions=" + encodeURIComponent(careInstructions) +
             "&offerDescription=" + encodeURIComponent(offerDescription) +
             "&onlyAtMacys=" + onlyAtMacys +
             "&legalOne=" + legalOne +
             "&legalOneExplain=" + legalOneExplain +
             "&legalTwo=" + legalTwo +
             "&legalTwoExplain=" + legalTwoExplain +
             "&legalThree=" + legalThree +
             "&legalThreeExplain=" + legalThree +
             "&legalFour=" + legalFour +
             "&fifty=" + fifty +
            //"&createdBy=" + userId


            "&offerId=" + offerId +
            "&merchId=" + merchId +
            "&adID=" + adId +
            "&eventID=" + eventID +
            "&adNum=" + adNum
            var ajaxMaster = new AjaxMaster(sql, "Puma.updateMerchFormForCutData(data)", "", "btiDispatcher.aspx");



            sql = "action=updateMerchFormForCut&sql=" + encodeURIComponent(msql);

            //objAjaxAd.SendQuery(sql);
            // "[t0].[signedByUserID]," +
            // "[t0].[signedStatus]," +
            //"[t0].[dateSigned]," + 
            //"[t0].[signedLastByUserID]," +
            //"[t0].[dateLastSigned1]," +
            //"[t0].[signedLastStatus]" +
            objAjaxAd.main_flag = "updateMerchFormForCutData";

            objAjaxAd.SendQuery(sql);

            //var ajaxMaster = new AjaxMaster(sql, "Puma.updateMerchFormForCutData(data)", "", "puma_core.aspx");
        }
    }
}

最佳答案

onClick 属性中只写入 " 而不是 \",或者直接省略引号:

onClick=Puma.saveTheCut()

字符\在HTML中没有特殊作用;这只是另一个 Angular 色。因此,当您有 onClick=\"Puma.saveTheCut()\" 时,实际属性值为 \"Puma.saveTheCut()\",这不起作用当然,正如您可以通过查看浏览器的开发人员工具中的控制台看到的那样。您应该会看到类似以下内容的内容:

SyntaxError: illegal character

\"Puma.saveTheCut()\"

(或者在测试 Agony 的 jsfiddle 时使用 \"yup()\")。

事实上,该代码不应在任何浏览器中运行,并且在我的 IE 10 中也不起作用。

关于javascript - HTML 按钮操作在 Safari 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19727463/

相关文章:

javascript - 幻灯片放映到下拉列表

Jquery UI 模态对话框在 IE6 和 IE7 中不起作用

在 Internet Explorer <= 8 中以编程方式调用时,javascript onclick 事件不会冒泡

javascript - 当数据源是数组时,jQuery DataTables 刷新网格

javascript - Vue2 回调中发布 axios 请求无法正常工作

javascript - 使用 javaScript 查找字符串中重复单词每次出现的起始索引的最佳方法

html - 动画结束后短暂的卡顿

javascript - 如何使用 JQuery 获取 HTML 表单数据并写入 XML?

Javascript - 如何替换 anchor 的 href 包含的特定出现?

javascript - 每当离开元素时,qTip2 总是关闭