GVKun编程网logo

从函数中的TypeError开始(函数typedef)

10

对于从函数中的TypeError开始感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍函数typedef,并为您提供关于Chrome中的“未捕获的TypeError:非法调用”、is_authen

对于从函数中的TypeError开始感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍函数typedef,并为您提供关于Chrome中的“未捕获的TypeError:非法调用”、is_authenticated()引发TypeError TypeError:'bool'对象不可调用、javascript – 具有大数据库的Typeahead.js给出了未捕获的TypeError:$(…).typeahead不是函数、javascript-未捕获的typeerror $(…).swipe不是函数的有用信息。

本文目录一览:

从函数中的TypeError开始(函数typedef)

从函数中的TypeError开始(函数typedef)

这是代码:

    def readFasta(filename):        """ Reads a sequence in Fasta format """        fp = open(filename, ''rb'')        header = ""        seq = ""        while True:            line = fp.readline()            if (line == ""):                break            if (line.startswith(''>'')):                header = line[1:].strip()            else:                seq = fp.read().replace(''\n'','''')                seq = seq.replace(''\r'','''')          # for windows                break        fp.close()        return (header, seq)    FASTAsequence = readFasta("MusChr01.fa")

我得到的错误是:

TypeError: startswith first arg must be bytes or a tuple of bytes, not str

但是startswith根据文档,第一个参数应该是字符串…那么怎么回事?

我假设至少使用Python 3,因为我使用的是最新版本的LiClipse。

答案1

小编典典

这是因为您是以字节模式打开文件的,所以您调用bytes.startswith()而不是str.startswith()

你需要做的line.startswith(b''>''),这将使''>''一个字节的文字。

Chrome中的“未捕获的TypeError:非法调用”

Chrome中的“未捕获的TypeError:非法调用”

如何解决Chrome中的“未捕获的TypeError:非法调用”?

在您的代码中,您正在将本机方法分配给自定义对象的属性。当您调用时support.animationFrame(function () {}),它将在当前对象(即支持)的上下文中执行。为了使本机requestAnimationFrame函数正常工作,必须在的上下文中执行它window

因此,此处的正确用法是 support.animationFrame.call(window, function() {});

警报也会发生相同的情况:

var myObj = {
  myAlert : alert //copying native alert to an object
};

myObj.myAlert(''this is an alert''); //is illegal
myObj.myAlert.call(window, ''this is an alert''); // executing in context of window

另一个选择是使用Function.prototype.bind(),它是ES5标准的一部分,并且在所有现代浏览器中都可用。

var _raf = window.requestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        window.oRequestAnimationFrame;

var support = {
   animationFrame: _raf ? _raf.bind(window) : null
};

解决方法

当我用requestAnimationFrame下面的代码来做一些本机支持的动画时:

var support = {
    animationFrame: window.requestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        window.oRequestAnimationFrame
};

support.animationFrame(function() {}); //error

support.animationFrame.call(window,function() {}); //right

直接致电support.animationFrame会给…

未捕获的TypeError:非法调用

在Chrome中。为什么?

is_authenticated()引发TypeError TypeError:'bool'对象不可调用

is_authenticated()引发TypeError TypeError:'bool'对象不可调用

我尝试is_authenticated()在视图中使用,但收到错误`TypeError:’bool’对象不可调用。为什么会出现此错误,我该如何解决?

@auth.before_app_requestdef before_request():    if current_user.is_authenticated() \            and not current_user.confirmed \            and request.endpoint[:5] != ''auth.'' \            and request.endpoint != ''static'':        return redirect(url_for(''auth.unconfirmed''))

答案1

小编典典

当您尝试表现对象的方法或功能时,会发生“对象不可调用”错误。

在这种情况下:

current_user.is_authenticated()

您将current_user.is_authenticated表现为一种方法,而不是一种方法。

您必须以这种方式使用它:

current_user.is_authenticated

您在方法或函数(而不是对象)之后使用“()”。

在某些情况下,类可能实现了__call__也可以调用对象的函数,因此它将是可调用的。

javascript – 具有大数据库的Typeahead.js给出了未捕获的TypeError:$(…).typeahead不是函数

javascript – 具有大数据库的Typeahead.js给出了未捕获的TypeError:$(…).typeahead不是函数

在我的项目中,typeahead.js给出错误:

Uncaught TypeError: $(…).typeahead is not a function

PHP

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="public/js/typeahead.js"></script>
<script>
jQuery(document).ready(function() {
var offset = 250;
var duration = 300;
jQuery(window).scroll(function() {
    if (jQuery(this).scrollTop() > offset) {
        jQuery('.back-to-top').fadeIn(duration);
    } else {
        jQuery('.back-to-top').fadeOut(duration);
    }
});

jQuery('.back-to-top').click(function(event) {
    event.preventDefault();
    jQuery('html,body').animate({scrollTop: 0},duration);
    return false;
});
$('input.search').typeahead({
    name: 'companyName',remote:'ser_sug.PHP?key=%QUERY',limit : 10
});
});
</script>
<style type="text/css">
.bs-example{
font-family: sans-serif;
position: relative;
margin: 50px;
}
.typeahead,.tt-query,.tt-hint {
border: 2px solid #CCCCCC;
border-radius: 8px;
font-size: 24px;
height: 30px;
line-height: 30px;
outline: medium none;
padding: 8px 12px;
width: 396px;
}
.typeahead {
background-color: #FFFFFF;
}
.typeahead:focus {
border: 2px solid #0097CF;
}
.tt-query {
Box-shadow: 0 1px 1px rgba(0,0.075) inset;
}
.tt-hint {
color: #999999;
}
.tt-dropdown-menu {
background-color: #FFFFFF;
border: 1px solid rgba(0,0.2);
border-radius: 8px;
Box-shadow: 0 5px 10px rgba(0,0.2);
margin-top: 12px;
padding: 8px 0;
width: 422px;
}
.tt-suggestion {
font-size: 24px;
line-height: 24px;
padding: 3px 20px;
}
.tt-suggestion.tt-is-under-cursor {
background-color: #0097CF;
color: #FFFFFF;
}
.tt-suggestion p {
margin: 0;
}
</style>
</head>
<div>
            <divhttps://www.jb51.cc/tag/heading/" target="_blank">heading">
                <h3https://www.jb51.cc/tag/heading/" target="_blank">heading">Search Ceramic</h3>
            </div>
            <form role="form"action="<?PHP echo SLASHES;?>search/" method="get">
                <div>
                    <input name="companyName" type="text" value="" placeholder="Company name"id="searchid">
                </div>
                <div>
                    <select name="category">
                        <option selected value="">Select Category</option>
                        <?PHP
                            $categoryResult = MysqL_query("SELECT * FROM `category` where flag = 1 order by `sequence`");
                            while($categoryRow = MysqL_fetch_assoc($categoryResult))
                                echo '<option value="'.$categoryRow['cid'].'">'.$categoryRow['cat_name'].'</option>';
                        ?>
                    </select>
                </div>
                <div>
                    <select name="productSize" id="productSize">
                        <option selected value="">Select Size(CentiMeter)</option>
                        <?PHP
                            $sizeResult = MysqL_query("SELECT * FROM sizes ORDER BY sequence");
                            while($sizeRow = MysqL_fetch_assoc($sizeResult))
                                echo '<option value="'.$sizeRow['id'].'">'.$sizeRow['inch'].'</option>';
                        ?>
                    </select>
                </div>
                <div>
                    <input name="location" type="text" value="" placeholder="Addr / city / state / country / pin">
                </div>
                <button type="submit">Search</button>
            </form>
        </div>
    </div>

sur_sug.PHP

<?PHP
MysqL_connect('localhost','username','pass');
MysqL_select_db("database");
$key=$_GET['key'];
$array = array();
$query=MysqL_query("select com_name from company_details where com_name LIKE '%{$key}%'");
while($row=MysqL_fetch_assoc($query))
{
  $array[] = $row['com_name'];
}
echo json_encode($array);
?>

我试图把我的$(文档).ready在一个不同的地方,但它给出以下错误:

请帮帮我.

解决方法

它与数据量无关,但是没有找到public / js / typeahead.js

将其更改为/js/typeahead.js,它将正常工作

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="/js/typeahead.js"></script>
<script>
  // ...

javascript-未捕获的typeerror $(…).swipe不是函数

javascript-未捕获的typeerror $(…).swipe不是函数

我试图在博客中创建可滑动菜单,这是我的代码:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="https://www.googledrive.com/host/0B2Iusn9ixPQ2cFFldHoweXRsWms"></script>


<script type="text/javascript">
      $(window).load(function(){
        $("[data-toggle]").click(function() {
          var toggle_el = $(this).data("toggle");
          $(toggle_el).toggleClass("open-sidebar");
        });
         $(".swipe-area").swipe({
              swipestatus:function(event, phase, direction, distance, duration, fingers)
                  {
                      if (phase=="move" &amp;&amp; direction =="right") {
                           $(".container").addClass("open-sidebar");
                           return false;
                      }
                      if (phase=="move" &amp;&amp; direction =="left") {
                           $(".container").removeClass("open-sidebar");
                           return false;
                      }
                  }
          }); 
      });

    </script>

并且Iam在“ $(”.swipe-area“).swipe({”:未捕获的typeerror $(…).swipe不是函数

请帮忙,
谢谢

解决方法:

尝试这个

<html>
<head>

<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
$(document).on("pagecreate","#pageone",function(){
  $("p").on("swipe",function(){
    $(this).hide();
  });                       
});
</script>
</head>
<body>

<div data-role="page" id="pageone">
  <div data-role="main">
    <p>If you swipe me, I will disappear.</p>
    <p>Swipe me away!</p>
    <p>Swipe me too!</p>
  </div>
</div> 

</body>
</html>

更新-意外令牌

您的代码在下面的行中有语法错误

swipestatus:function(event, phase, direction, distance, duration, fingers)

正确的语法-您可以通过以下方式定义swipestatus函数

var swipestatus  = function(event, phase, direction, distance, duration, fingers)

今天关于从函数中的TypeError开始函数typedef的介绍到此结束,谢谢您的阅读,有关Chrome中的“未捕获的TypeError:非法调用”、is_authenticated()引发TypeError TypeError:'bool'对象不可调用、javascript – 具有大数据库的Typeahead.js给出了未捕获的TypeError:$(…).typeahead不是函数、javascript-未捕获的typeerror $(…).swipe不是函数等更多相关知识的信息可以在本站进行查询。

本文标签: