$a = 'how are you';
if (strpos($a,'are') !== false) {
echo 'true';
}
Run Code Online (Sandbox Code Playgroud)
在PHP中,我们可以使用上面的代码来检查字符串是否包含特定的单词,但是如何在JavaScript/jQuery中执行相同的功能呢?
下面的代码将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) 在每个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) 是的http://anything/%%30%30,即使在悬停时,该链接也会崩溃我的Google Chrome浏览器.
它是如何工作的?
我正在尝试在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) 生成具有给定节点数的随机简单(无平行边或自循环)无向图的最佳算法是什么,其中每个节点具有不小于min且不大于max?的多个边.
例如,如果min = 2和max = 5,我想要一个图表,其中大约25%的节点有2个边,大约25%的节点有3个边,大约25%的节点有4个边,大约25%的节点有5个边缘.
algorithm graph-theory graph time-complexity graph-algorithm
我试图通过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
你有什么想法?
我从一个非常挑剔的人那里听说,在一个线程中抛出(并且未被捕获)的异常正在传播到父线程.真的吗?我尝试过类似的东西,但无法在创建线程中捕获异常.
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) 我正在尝试从 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) $(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 ×5
c# ×2
.net ×1
algorithm ×1
angular ×1
angular-cli ×1
asp.net ×1
base-url ×1
crash ×1
date ×1
download ×1
dynamic ×1
exception ×1
github ×1
graph ×1
graph-theory ×1
html5 ×1
html5-canvas ×1
image ×1
input ×1
jquery ×1
macos ×1
magento ×1
object ×1
security ×1
url-scheme ×1
windows ×1