小编416*_*577的帖子

JavaScript/jQuery - 如何检查字符串是否包含特定单词

$a = 'how are you';
if (strpos($a,'are') !== false) {
    echo 'true';
}
Run Code Online (Sandbox Code Playgroud)

在PHP中,我们可以使用上面的代码来检查字符串是否包含特定的单词,但是如何在JavaScript/jQuery中执行相同的功能呢?

javascript jquery

22
推荐指数
7
解决办法
10万
查看次数

使用Javascript在IE中将画布下载到Image

下面的代码将canvas转换为图像,并在IE以外的浏览器中下载(我使用的是IE9).IE Code在新标签中打开DataURL.但是,它不可下载.

     if(navigator.appName == "Microsoft Internet Explorer")
              {
                  somehtml1= document.createElement("img");
                  somehtml1.id="imgid";somehtml1.name="imgname";
                  somehtml1.src=canvas.toDataURL("image/png");
                  document.body.appendChild(somehtml1);

                  window.win = open (somehtml1.src);
                   setTimeout('win.document.execCommand("SaveAs")', 500);
                     }           
              else
                       {
                             somehtml= document.createElement("a");
 somehtml.href = canvas.toDataURL("image/png");
 somehtml.download = "test.png"; 

}
Run Code Online (Sandbox Code Playgroud)

javascript image download html5-canvas

11
推荐指数
2
解决办法
1万
查看次数

启动应用程序(如果已安装)或重定向下载 - 窗口

Stack Overflown这个问题中提到:

在每个repo上,GitHub都有一个标记为"Clone in Desktop"的按钮(例如:https://github.com/github/developer.github.com).如果您安装了GitHub for Mac,则href类似于"github-mac:// openRepo/https://github.com/github/developer.github.com ".这将打开GitHub for Mac并提供克隆回购.如果不这样做,则href为" http://mac.github.io ".这是GitHub for Mac的下载页面.我想在我的网站上做类似的事情:如果已安装,请打开我的应用程序,如果没有则重定向下载.如何才能最好地完成?

答案是关于Github Conduit,但据我所知,Github Conduit仅适用于Mac的Github.

我有同样的问题,仅适用于Windows操作系统.GitHub如何知道GitHub是否安装在计算机上?


正如deepcurious在说他们的答案,我们需要使用下面的代码,如果协议注册的检查:

$("a[href*='github-windows://']").click(function(e) {
    var el = $(this);
    setTimeout(function() {
        window.location = el.data("data-href-alt");
    }, 200);

    // once you do the custom-uri, it should properly execute the handler, otherwise, the settimeout that you set before will kick in
    window.location = el.data("href");

    e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)

我有以下HTML链接:

<a href="github-windows://openRepo/https://github.com/jquery/api.jqueryui.com" data-href-alt="https://www.example.com/app-not-installed">Clone …
Run Code Online (Sandbox Code Playgroud)

windows macos github url-scheme github-for-windows

10
推荐指数
1
解决办法
823
查看次数

http:// a/%% 30%30如何工作?

是的http://anything/%%30%30,即使在悬停时,该链接也会崩溃我的Google Chrome浏览器.

它是如何工作的?

security crash google-chrome

10
推荐指数
1
解决办法
2万
查看次数

来自<input type = date>的JavaScript日期对象

我正在尝试在focus.add_days函数中创建一个javascript日期对象,以便在元素中的给定日期添加一些日期.问题是javascript对象不期望字符串"Ymd"所以如何创建日期对象而不将字符串"Ymd"解析成片段,或者是唯一的方法?

trigger = {
fecha_ini: function(){
    $('input[name="fecha_ini"]').on('change',function(){
      console.log('hi');
      var fecha_fin = $(':input [name=fecha_fin]');
      var min = $(this).val();
      //here is where i pass the "Y-m-d" string as the date argument
      var max = fechas.add_days(min,31*4);
      fecha_fin.attr('min',min);
      fecha_fin.attr('max',max);
      fecha_fin.val('');
    })
  }
};

fechas = {
  add_days: function addDays(date, days) {
    //here is where i use the string "Y-m-d" to create the date object, but obviusly doesnt work
    var result = new Date(date);
    result.setDate(date.getDate() + days);
    return result;
}
};

trigger.fecha_ini();
Run Code Online (Sandbox Code Playgroud)

javascript html5 date input object

9
推荐指数
3
解决办法
7774
查看次数

生成随机网络的算法

生成具有给定节点数的随机简单(无平行边或自循环)无向图的最佳算法是什么,其中每个节点具有不小于min且不大于max?的多个边.

例如,如果min = 2max = 5,我想要一个图表,其中大约25%的节点有2个边,大约25%的节点有3个边,大约25%的节点有4个边,大约25%的节点有5个边缘.

algorithm graph-theory graph time-complexity graph-algorithm

9
推荐指数
1
解决办法
302
查看次数

如何通过Javascript获取Magento baseUrl然后在jquery.hello-lightbox.min中使用它?

我试图通过head.phtml文件中的javascript获取Magento BaseUrl,然后在jquery.hello-lightbox.min文件中使用它,我需要baseUrl来获取一些图像.

这是我在head.phtml文件中的内容:

<?php $baseUrl = $this->getBaseUrl() ; ?>

<script type="text/javascript">

var baseUrl = <?php echo $baseUrl ; ?>

function getBaseUrl(baseUrl)

</script>
Run Code Online (Sandbox Code Playgroud)

然后在/js/jquery.hello-lightbox.min我有:

(function($){

function getBaseUrl(baseurl)
{
var domain = baseurl
}

var urrl = 'http://'+domain+'/skin/frontend/default/customtheme/images/lightbox/';

  $.fn.lightBox=function(settings)settings=jQuery.extend({overlayBgColor:'#000',overlayOpacity:0.8,fixedNavigation:false,imageLoading: urrl+'lightbox-ico-loading.gif',imageBtnPrev:urrl+'lightbox-btn-prev.gif', . . . . . . . . . . 
Run Code Online (Sandbox Code Playgroud)

但这不起作用.事实上,似乎我甚至无法将head变量$ baseUrl传递给head.phtml中的var baseUrl

你有什么想法?

javascript magento base-url

8
推荐指数
1
解决办法
2万
查看次数

多线程应用程序中的异常.

我从一个非常挑剔的人那里听说,在一个线程中抛出(并且未被捕获)的异常正在传播到父线程.真的吗?我尝试过类似的东西,但无法在创建线程中捕获异常.

    static void Main(string[] args)
    {
        ParameterizedThreadStart pts = 
           new ParameterizedThreadStart(ThreadMethod);
        try
        {
            Thread t = new Thread(pts);
            t.Start(new object());
            Console.ReadLine();
        }
        catch (Exception ex) //the exception is not caught
        {
            Debugger.Break();
        }
    }


    static void ThreadMethod(object @object)
    {
        Thread.Sleep(2000);
        throw new IndexOutOfRangeException();
        Thread.CurrentThread.Abort();
    }
Run Code Online (Sandbox Code Playgroud)

.net c# multithreading exception

7
推荐指数
1
解决办法
7717
查看次数

尝试构建时出现 Angular 8 到 9 升级错误

我正在尝试从 Angular 8 升级到 9,但在执行 ng build 时出现此错误。看起来问题出在 vendor.js 中的 babel 包中。

在此处输入图片说明

[error] SyntaxError: C:\Dev\allverse3\ClientApp\vendor-es2015.js: 'with' in strict mode (139204:4)

[0m [90m 139202 | [39m  [33mWindow_run[39m[33m:[39m [36mfunction[39m _run(code[33m,[39m file) {[0m
[0m [90m 139203 | [39m    [36mif[39m (file) code [33m+=[39m [32m'\n//@ sourceURL='[39m [33m+[39m file[33m;[39m[0m
[0m[31m[1m>[22m[39m[90m 139204 | [39m    [36mwith[39m([36mthis[39m) eval(code)[33m;[39m[0m
[0m [90m        | [39m    [31m[1m^[22m[39m[0m
[0m [90m 139205 | [39m  }[33m,[39m[0m
[0m [90m 139206 | [39m  [33mEventHandlerBuilder_build[39m[33m:[39m [36mfunction[39m build() {[0m
[0m [90m 139207 | [39m    [36mtry[39m {[0m
    at Parser.raise (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:7017:17)
    at …
Run Code Online (Sandbox Code Playgroud)

angular-cli angular

7
推荐指数
1
解决办法
1266
查看次数

Javascript将值传递给asp.net

  $(document).ready(function () {
    $("#MainContent_ddlFieldName").live("change", function () {
                 var id = $(this).val();
                 var name = $(this + "option:selected").text();

                 $('#<%= lblValue.ClientID %>').text(name);
                 $('#<%= lblType.ClientID %>').text(id);
             });
         });


<asp:Label ID="lblValue" runat="server" Text="" Visible="true"></asp:Label>
 <asp:Label ID="lblType" runat="server" Text="" Visible="true"></asp:Label>



protected void btnSearch_Click(object sender, EventArgs e)
        {
             string strValue = lblValue.Text;
             string strType = lblType.Text;
        }
Run Code Online (Sandbox Code Playgroud)

我使用javascript和Asp.Net来获取下拉列表的值并将其放在标签中.它实际上显示标签的文本,当我点击一个按钮或事件,我得到它以前的值w/c是""

谁能帮我这个.

谢谢

javascript c# asp.net dynamic

6
推荐指数
1
解决办法
1123
查看次数