小编Pat*_*tec的帖子

使用附加到div的javascript创建iframe

我想用常规的javascript加载/追加iframe到div中.我可以使用JQuery做到这一点没有问题,但我不想包含js文件.我一直收到错误'document.getElementById("ad54")'(或者我分配div的任何id).我有以下代码:

var link = "http://www.google.com"
var iframe = document.createElement('iframe');
iframe.frameBorder=0;
iframe.width="300px";
iframe.height="250px";
iframe.id="randomid";
iframe.setAttribute("src", link);
document.getElementById("ad54").appendChild(iframe);

<div id="ad54"></div>
Run Code Online (Sandbox Code Playgroud)

html javascript iframe

13
推荐指数
1
解决办法
5万
查看次数

使用常规javascript检测Jquery,如果不存在则动态加载它

我需要代码使用常规javascript来检测JQuery是否存在,如果没有,从谷歌或其他网站加载JQuery文件

更新两个工作解决方案(只需在此复制和粘贴工作代码):

来自Claudio Redi

window.jQuery || document.write("<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'>\x3C/script>")
Run Code Online (Sandbox Code Playgroud)

来自Rob Darwin

var jQueryScriptOutputted = false;
function initJQuery() {
    if (typeof(jQuery) == 'undefined') {
        if (! jQueryScriptOutputted) {
            jQueryScriptOutputted = true;
            document.write("<scr" + "ipt type=\"text/javascript\" src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js\"></scr" + "ipt>");
        }
        setTimeout("initJQuery()", 50);
    }
}
initJQuery();
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

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

按生日排序,无视年份

如何在ORDER BY生日的情况下查询完全无视年份的情况.我需要在今天的ASC或DESC中消除/忽视年份和ORDER BY出生日期和出生日期.

以下内容不起作用,因为生日的年代发挥作用.下面的例子显示了当年度被认为会发生什么:

John   01/02/1974
Billy  11/15/2000
Ally   06/25/2008

SELECT * FROM users ORDER BY birthdate
Run Code Online (Sandbox Code Playgroud)

按生日订购时的预期结果:

John   01/02/1974
Ally   06/25/2008
Billy  11/15/2000
Run Code Online (Sandbox Code Playgroud)

sql t-sql sql-server-2005 sql-server-2008

4
推荐指数
2
解决办法
2981
查看次数

使用PHP获取&lt;script type =“ application / ld + json”&gt;的内容

我找不到Vine的API来获取页面内容的标题,描述和图像。JSON位于页面主体的script标记中。如何使用PHP获取此脚本标签的内容(JSON)以便可以对其进行解析?

藤页:

https://vine.co/v/igO3EbIXDlI
Run Code Online (Sandbox Code Playgroud)

来自页面来源

<script type="application/ld+json">
            {
              "@context": "http://schema.org",
              "@type": "SocialMediaPosting",
              "url": "https://vine.co/v/igO3EbIXDlI",
              "datePublished": "2016-03-01T00:58:35",
              "author": {
                "@type": "Person",
                "name": "MotorAddicts\u2122",
                "image": "https://v.cdn.vine.co/r/avatars/39FEFED72B1242718633613316096_pic-r-1439261422661708f3e9755.jpg.jpg?versionId=LPjQUQ4KmTIPLu3iDbXw4FipgjEpC6fw",
                "url": "https://vine.co/u/989736283540746240"
              },
              "articleBody": "Mmm...  Black black blaaaaack!! \ud83d\ude0d ( Drift \u53d1 )",
              "image": "https://v.cdn.vine.co/r/videos/98C3799A811316254965085667328_SW_WEBM_14567938452154dc600dbde.webm.jpg?versionId=wPuaQvDxnpwF7KjSGao21hoddooc3eCl",
              "interactionCount": [{
                "@type": "UserInteraction",
                "userInteractionType": "http://schema.org/UserLikes",
                "value": "1382"
              }, {
                "@type": "UserInteraction",
                "userInteractionType": "http://schema.org/UserShares",
                "value": "368"
              }, {
                "@type": "UserInteraction",
                "userInteractionType": "http://schema.org/UserComments",
                "value": "41"
              }, {
                "@type": "UserInteraction",
                "userInteractionType": "http://schema.org/UserViews",
                "value": "80575"
              }],

              "sharedContent": {
                "@type": "VideoObject",
                "name" : "Mmm...  Black black …
Run Code Online (Sandbox Code Playgroud)

php parsing json vine

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

在选择更改时使用JQuery选择文件后清除文件输入字段

使用名为filestyle的Jquery插件:http://www.appelsiini.net/projects/filestyle.我有一个id为adtype的选择框.如果所选选项的值为7,则会禁用ID为"adfile"的文件输入.

当用户已经选择了文件时,问题就变成了.我找不到清除文件输入然后禁用它的方法.$( '#adfile')VAL( '').不起作用.

JQUERY

$(function(){
  $('#adtype').change(function(){
    if($('#adtype option:selected').val()==="7"){
      $('#adfile').val('');
      $("#adfile").prop('disabled', true);
    }else{
      $("#adfile").prop('disabled', false);
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

HTML

<form id="someform" action="somepage" method="post">
  <select name="selectstuff" id="adtype">
    <option value="1">one</option>
    <option value="5">five</option>
    <option value="7">seven</option>
  </select>

  <input type="file" id="adfile" value="" />

  <input type="submit" value="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)

html forms jquery

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

条件WHERE子句

我需要WHERESQL Server中的条件子句的解决方案.我无法弄清楚如何WHERE根据声明的变量将函数添加到子句中.我将条件部分与所需的逻辑括起来

DECLARE @distance bigint
DECLARE @photosneeded bigint

SET @distance * 50

SELECT * FROM users u
WHERE
  [IF @distance > 0 THEN distance_function(lat1,lon1,lat2,lon2)<=@distance END]
  AND
  [IF @photosneeded>0 THEN u.photo IS NOT NULL AND u.photo <>'' END]
Run Code Online (Sandbox Code Playgroud)

sql sql-server sql-server-2008

0
推荐指数
1
解决办法
1587
查看次数

在使用jquery验证后正常提交表单

我使用的是从这里jquery.form.js:http://www.malsup.com/jquery/form/.我想在提交之前验证表单输入文本的文本.验证转到'search_validate.php'.这部分工作正常.如果验证通过,则表单操作会更改.这也有效.

在更改操作属性后使表单正常提交不起作用.浏览器永远不会进入'/ videos/search /'页面.它保持在同一页面上.我看到'/ videos/search /'页面一遍又一遍地加载Firebug.

<form id="search" method="post" action="">
<input type="text" id="query" />
<input type="image" id="searchmag" src="blah.jpg" ?>
</form>

<script>
$(function(){
  $('#searchmag').click(function(){
    $('#search').attr('action','/search_validate.php');

    $('#search').ajaxForm(function(data, textStatus){
      if ((data.indexOf('letters & numbers only')>-1)) {
      $('#query').css('color','#FF0000').val(data); 

      $("#query").unbind("click").click(function(){
        $('#query').css('color','#848484').val('');
      });
    } else {
      $('#search').attr('action','/videos/search/' + $('#query').val());
      $('#search').submit();
    }
    });
  });
});
</script>
Run Code Online (Sandbox Code Playgroud)

html javascript forms jquery

0
推荐指数
1
解决办法
7101
查看次数