小编Max*_*rai的帖子

Javascript字段值长度

我正在做这样的事情:

alert(document.getElementById('cardNumber').value);
Run Code Online (Sandbox Code Playgroud)

它会提醒cardNumber值.但我需要它的长度:

alert(document.getElementById('cardNumber').value.lenght);
Run Code Online (Sandbox Code Playgroud)

未定义

为什么?

javascript string

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

加载带有西里尔符号的 url

我必须加载一些带有西里尔符号的 url。我的脚本应该适用于这个:

http://wincode.org/%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC%D0%B8%D1%80%D0 %BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5/

如果我将在浏览器中使用它,它将被替换为普通符号,但 urllib 代码失败并出现 404 错误。如何正确解码这个网址?


当我直接在代码中使用那个 url 时,比如 address = 'that address',它工作得很好。但是我使用解析页面来获取这个 url。我有一个包含西里尔字母的 url 列表。也许他们的编码不正确?这是更多代码:

requestData = urllib2.Request( %SOME_ADDRESS%, None,  {"User-Agent": user_agent})
requestHandler = pageHandler.open(requestData)

pageData = requestHandler.read().decode('utf-8')
soupHandler = BeautifulSoup(pageData)

topicLinks = []
for postBlock in soupHandler.findAll('a', href=re.compile('%SOME_REGEXP%')):
    topicLinks.append(postBlock['href'])

postAddress = choice(topicLinks)

postRequestData = urllib2.Request(postAddress, None,  {"User-Agent": user_agent})
postHandler = pageHandler.open(postRequestData)
postData = postHandler.read()

  File "/usr/lib/python2.6/urllib2.py", line 518, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
Run Code Online (Sandbox Code Playgroud)

python url urllib

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

Init var没有复制构造函数

我有一些没有复制构造函数的类(Window)(它是私有的).我无法理解如何在我自己的类中初始化此类的变量:

class MyClass
{
   Window obj; // Hasn't copy constructor
   public:
      void init()
      {
         obj = Window(/* constructor params */); // [error]
         obj(/* constructor params */); // [error]
      }
}
Run Code Online (Sandbox Code Playgroud)

错误1:initializing argument 1 of ‘Window::Window(WindowHandle, const sf::WindowSettings&)’

错误2:‘NonCopyable& NonCopyable::operator=(const NonCopyable&)’ is private

但它以这种方式工作:

Window obj(/* constructor params */);
Run Code Online (Sandbox Code Playgroud)

c++ constructor copy init

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

如何将函数引用传递给参数

我正在使用boost :: function来创建函数引用:

typedef boost::function<void (SomeClass &handle)> Ref;
someFunc(Ref &pointer) {/*...*/}

void Foo(SomeClass &handle) {/*...*/}
Run Code Online (Sandbox Code Playgroud)

Foo传递给someFunc的最佳方法是什么?我尝试过类似的东西:

someFunc(Ref(Foo));
Run Code Online (Sandbox Code Playgroud)

c++ boost reference function

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

宏观和功能中的'this'指针

我有一些代码使用调用此代码的类的'this'指针.例如:

Some::staticFunction<templateType>(bind(FuncPointer, this, _1));
Run Code Online (Sandbox Code Playgroud)

这是我从boost调用bind函数.但没关系.现在我必须包装此代码.我做了一个宏:

#define DO(Type, Func) Some::staticFunction<Type>(bind(FuncPointer, this, _1));
Run Code Online (Sandbox Code Playgroud)

并且编译器将此代码插入到调用此宏的类中,因此'this'来自调用者.但我不想使用宏和首选功能(内联).但如何解决'这'传递.我可以在内联函数中使用它,如在宏中,或者我必须手动传递它吗?

c++ macros inline this

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

私人构造函数

我有一个类的对象,它有私有构造函数:

class CL_GUIComponent
{
    // ...
    private:
    CL_SharedPtr<CL_GUIComponent_Impl> impl;
    CL_GUIComponent(CL_GUIComponent &other);
    CL_GUIComponent &operator =(const CL_GUIComponent &other);
    CL_GraphicContext dummy_gc;
};
Run Code Online (Sandbox Code Playgroud)

我有一个类,它有一个指向我之前描述的类型的对象的指针.

class Some
{
   private:
       CL_GUIComponent *obj;
   public:
       CL_GUIComponent getComp() { return *obj; }
}
Run Code Online (Sandbox Code Playgroud)

但是这段代码调用了错误:

In member function ‘CL_GUIComponent Some::getComp()’:
error: ‘CL_GUIComponent::CL_GUIComponent(CL_GUIComponent&)’ is private
error: within this context
Run Code Online (Sandbox Code Playgroud)

我如何存储和获取该对象?

c++ constructor private

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

python中的列表和文件

我正在使用readlinespython中的方法来获取所有数据行的列表.现在我不想从该列表中访问一些索引:

file = open('article.txt', 'r')
data = file.readlines()
print data.index(1)
Error: data isn't a list
Run Code Online (Sandbox Code Playgroud)

怎么了?

python file list

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

使用Mathematica进行图像处理

我在上一篇文章之后创建了这个主题.我无法运行以下代码(由@belisarius编写):

a = Image["path/file.png"]
b = Image@ArrayPad[ImageData@a, {{40, 0}, {40}, {0}}, {1, 1, 1}];
f[image_, angleMult_] := ImageForwardTransformation[image, (
    fi = ArcTan[Abs[#[[2]]/(#[[1]] - .5)]];
    fi1 = angleMult fi (#[[1]]^2 + #[[2]]^2)/2;
    {(1/2 - Sin[fi1] #[[2]] - Cos[fi1]/2 + 
       Cos[fi1] #[[1]]), -Sin[fi1]/2 + Sin[fi1] #[[1]] + 
      Cos[fi1] #[[2]]}) &]
t = Table[f[b, x], {x, 0, .2, .02}];
t1 = Reverse@t;
Export["anim.gif", Join[t, t1], "DisplayDurations" -> .15];
Import["anim.gif", "Animation"]
Run Code Online (Sandbox Code Playgroud)

以下是错误列表:

ArrayPad::depth: Padding amount {{40,0},{40},{0}} should specify padding in no more …
Run Code Online (Sandbox Code Playgroud)

linux wolfram-mathematica

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

Python和数组

我知道python是一种疯狂的语言,因为它的循环结构:)

所以,我有一个数字数组,但在字符串类型:

a = ['1', '40', '356', '...']
Run Code Online (Sandbox Code Playgroud)

我需要这个或该数组的副本,但使用float类型而不是字符串.唯一的问题是代码应该在一行中.

请帮帮我 :)

python arrays cycle

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

JavaScript和DOM

我无法理解这种情况:

我有一个网站模板,在标题中有代码:

$(document).ready(function () {
    $('#header').corner();
    ...
}
Run Code Online (Sandbox Code Playgroud)

corner()只是一个jQuery插件函数.但问题是:

("#header") is null
    $('#header').corner();
Run Code Online (Sandbox Code Playgroud)

它在主页面上工作,但在另一个页面上(使用相同的模板) - 不起作用.

要查看所有操作,请查看页面.您会看到标题(蓝色顶部div)四舍五入,并且firebug控制台中没有任何错误.现在转到页面.一切都有效,但这次不是主页面(它仍然使用相同的模板文件).

第三页,出现的错误,但还是一样的模板.怎么了?

javascript jquery dom

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